C语言编程,输入一行字符,分别统计出其中英文字母,空格,数字和其它字符的个数

如题所述

第1个回答  2013-11-20
以下程序在win-tc下调试通过 /* 输入一行文字 找出其中大写字母小写字母空格数字及其他字符各有多少 */ # include "stdio.h" # include "conio.h" void main(void) { int upper=0,lower=0,digit=0,space=0,other=0,i=0; char *p,s[80]; printf("\nInput a string:"); while ((s[i]=getchar())!='\n') i++; p=s; while(*p!='\n') {if((*p>='A')&&(*p<='Z')) upper++; else if((*p>='a')&&(*p<='z')) lower++; else if(*p==' '||*p==9) space++; else if((*p>='0')&&(*p<='9')) digit++; else other++; p++; } printf("upper case:%d lower case:%d ",upper,lower); printf("space:%d digit:%d other:%d ",space,digit,other); getch(); }
第2个回答  2020-03-09

C语言经典例子之统计英文、字母、空格及数字个数

相似回答