高手帮我看下这个简单C语言程序错在哪?

来源:百度知道 编辑:UC知道 时间:2024/05/09 07:29:37
题目是:输入一行字符,分别统计出其中的英文字母、空格、数字和其它字符的个数。在得到正确结果后,请修改程序使之能分别统计大小写字母、空格、数字和其它字符的个数。

谢谢~~~
我做的错在哪?
#include<stdio.h>
void main()
{char c;int a=0,b=0,m=0,n=0;
c=getchar();
for(;c!='\n';)
{if('A'<=c&&c<='Z')
a++;
else if('a'<=c&&c<='z')
b++;
else if(c==32)
m++;
else
n++;
}
printf("The number of capital letter is %d.\n",a);
printf("The number of small letter is %d.\n",b);
printf("The number of space is %d.\n",m);
printf("The number of else is %d.\n",n);
}

#include<stdio.h>
void main()
{char c;int a=0,b=0,m=0,n=0;
c=getchar();
for(;c!='\n';)
{if('A'<=c&&c<='Z')
a++;
else if('a'<=c&&c<='z')
b++;
else if(c==32)
m++;
else
n++;
c=getchar(); /*少了这个东东,你的只输入了一次,在循环里没有输入字符,无法退出循环,也达不到计划的目的*/
}
printf("The number of capital letter is %d.\n",a);
printf("The number of small letter is %d.\n",b);
printf("The number of space is %d.\n",m);
printf("The number of else is %d.\n",n);
}

你这个问题 只能输入一个 字符

你应该吧 c = getchar();
放到 for
循环里面。哈哈

#include<stdio.h>
void main()
{char c;int a=0,b=0,m=0,n=0;
c=getchar();
for(;c!='\n';)
{if('A'<=c&&c<='Z')
a++;
else if('a'<=c&&c<='z')
b++;
else if(c==32)<