统计各种字符个数
#include <stdio.h> #include <conio.h> int main(int argc, char * argv[]) { char ch; int letters = 0, space = 0, digit = 0, others = 0; printf("请输入一组字符串:\n"); while((ch=getchar())!='\n') { if(ch>'a' && ch < 'z' || ch >'A' && ch< 'Z') letters++; else if(ch == ' ') space++; else if(ch>='0' && ch<='9') digit++; else others++; } printf("英文个数为:%d,空格为:%d,数字为:%d,其他字符:%d", letters, space, digit, others); getch(); return 0; }
学习笔记转摘于:
丝酷网 http://www.pythonschool.com/