Input a line of characters in C language, and count the Chinese and English letters and spaces respectively
Note: while((c=getchar())!='\n') means that after entering a string of strings in the terminal, until the Enter is entered, the string is added to the memory buffer, and then the character is taken out and assigned in a loop to c! ! !
#include <stdio.h>
int main()
{
char c;
int space=0,letter=0,num=0,other=0;
while((c=getchar())!='\n')
{
if (c==' ')
space ++;
else if(c<='z'&&c>='a'||c<='Z'&&c>='A')
letter ++;
else if (c>='0'&&c<='9')
num ++;
else
other ++;
}
printf("space:%d\nletter:%d\nnum:%d\nother:%d\n",space,letter,num,other);
}
The result of entering a string in the terminal: