C language inputs a line of data and counts the number of English letters, spaces, numbers and other characters in it and outputs the result

#Input a line of data (including numbers, English letters, common characters, and spaces), count the number of English letters, spaces, numbers, and other characters and output the results; then output the numbers in order

##Code part:
#include <stdio.h>
#include <string.h>
int main()

{ char c[50],d[50]; int A,B,C,D,i,k,n; A=B=C=D=0;k=0; printf("Please enter a string of characters: "); gets©; n=strlen©; for(i=0;i<n;i++) //Statistics on strings through classification discussions. { if (c[i] >= 'a'&&c[i]<= 'z' || c[i] >= 'A'&&c[i] <= 'Z') { A ++; } else if (c [i] == ' ') { B++; } else if (c[i] >= '0'&&c[i]<= '9') { C++; } else { D++; } } printf("Number of letters: %d\nNumber of spaces:%d\nNumber of digits:%d\nOther characters:%d\n”,A,B,C,D); printf(“The numbers in this string are:”); for(i=0;i<n;i++) if (c[i] >= '0'&&c[i]<= '9') {printf(“%c”,c[i]); d[k ]=c[i]; k++; }
































return 0;
}

##running result:
running result

Guess you like

Origin blog.csdn.net/Deng7326/article/details/115238655