#include <stdio.h> int main(){ char c; //用户输入的字符 int shu=0;//字符总数 int letters=0, // 字母数目 space=0, // 空格数目 digit=0, // 整数数目 others=0; // 其他字符数目 printf("输入一些字符:"); while((c=getchar())!=‘\n‘){ // 每次读取一个字符,回车时结束 if(c>=‘a‘&&c<=‘z‘||c>=‘A‘&&c<=‘Z‘) letters++; else if(c==‘ ‘) space++; else if(c>=‘0‘&&c<=‘9‘) digit++; else others++; shu++; } printf("\n统计结果:\n字符总数=%d\n英文字母=%d\n空格=%d\n整数=%d\n其他字符=%d\n\n", shu,letters, space, digit, others); return 0; }
原文:https://www.cnblogs.com/xkdn/p/14881867.html