#include <stdio.h>int main () { char a=0; int num_count=0; int space_count=0; int other_count=0; //note Here, cannot be written A=getchar (), then while (a!= ' \ n '), so that only one line is entered, and then a dead Loop while ((A=getchar ())! = ' \ n ') { if (a>= ' 0 ' &&a<= ' 9 ' ) { num_count++; } else if (a== ' ') { space_ count++; } else { other_count++; } } printf ("num_count=%d\n", num_ count); printf ("space_count=%d\n", Space_count); printf ("Other_ Count=%d\n ", other_count); return 0;} Another method----Calling the function: #include <stdio.h> #include <ctype.h> //the white-space character, Call the Isspace () function, so call the header file Int main () { char str[20];   //this block has a limit on the input int num_count=0; int space_count=0 ; int other_count=0; char *p=str; gets (str); //Receive string while (*p) { if (*p> = ' 0 ' &&*p<= ' 9 ') { num_ Count++; } else if (Isspace (*p)) //Use the Isspace function to determine if it is a blank character { space_count++; } else { other_count++; } p++; } printf ("num_count=%d\n", Num_count); printf ("space_count=%D\n ", Space_count); printf (" other_count=%d\n ", other_count); return 0;}
This article from "Thanksgiving" blog, reproduced please contact the author!
Write a program statistic in the input string: numbers, whitespace characters, and the number of occurrences of all other characters