Kerugaki-Blog Park http://www.cnblogs.com/kailugaji/
1#include <stdio.h>2 3 voidMain () {4 intC, letter=0, num=0, blank=0, tab=0, enter=0, other=0, i=0, sum=0;5printf"Please input a string:\n");6 while((C=getchar ())! =EOF) {7sum++;8 if(c==' '){9++blank;//the number of space barTen } One Else if(c=='\ t'){ A++tab;//Number of tab keys - } - Else if(c=='\ n'){ the++enter;//number of Enter key - } - Else if((c>='A'&& c<='Z') || (c>='a'&& c<='Z')){ -++letter;//Number of letters + } - Else if(c>='0'&& c<='9'){ +++num;//Number of Numbers A } at Else++other;//number of other characters -i++; - } -printf"there is%d characters\n", sum); -printf"blank=%d, tab=%d, enter=%d, letter=%d, number=%d, other=%d\n", blank, tab, enter, letter, NUM, and other); - in}
The result is:
C language statistics A string of characters the space bar, TAB key, enter, letters, numbers and other characters (CTRL + Z terminating input)