C语言统计字符串字符类型数量
#include<stdio.h> int main() { char ch[20],*p; int upper=0,lower=0,digit=0,space=0,other=0; printf("请输入一行文字:\n"); gets(ch); p=ch; while(*p!='\0') { if(*p>='A'&&*p<='Z') upper++; else if(*p>='a'&&*p<='z') lower++; else if(*p>='0'&&*p<='9') digit++; else if(*p==' ') space++; else other++; p++; } printf("大写字母:%d\n",upper); printf("小写字母:%d\n",lower); printf("数字字符:%d\n",digit); printf("空格:%d\n",space); printf("其他字符:%d\n",other); return 0; }
原文地址: https://www.cveoy.top/t/topic/odvg 著作权归作者所有。请勿转载和采集!