以下程序在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();
}
温馨提示:答案为网友推荐,仅供参考