初学者~没搞懂为啥错了!
/*输入一串字符串,分别计算其中大写字母,小写字母,数字,空格,和其他字符的个数*/
#include<stdio.h>
#include<ctype.h>
main()
{
char a[20];
char *p;
int big,small,space,num,other;
p=a;
for(;*p=='\n';p++)
{
scanf("%c",p);
if(isupper(*p)==1) big++;
else{
if(islower(*p)==1) small++;
else{
if(*p==' ') space++;
else{
if(isprint(*p)==1) num++;
else other++;
}
}
}
}printf("big:%d\nsmall:%d\nspace:%d\nnum:%d\nother:%d\n",big,small,space,num,other);
}
运行结果big:2293560
small:2293504
space:4199392
num:0
other:0
[解决办法]
char a[20];
int big,small,space,num,other;
都需要初始化
for(;*p=='\n';p++)
循环的执行条件是 "*p == '\n'",没明白你啥意思
[解决办法]
for(;*p=='\n';p++)
???
改为for(;*p!='\n';p++)吧
还有就是没有初始化的问题,不然是由系统随机赋值,都赋值0先
[解决办法]
俺也是初学者,发现了你的基础问题~
1:没有初始化。
int big=0,small=0,space=0,num=0,other=0;
2:你的程序是要统计个数的。你没有给出明确的判断~或者是俺没有明白~一般用ASCII码判断~
3:要养成良好习惯啊兄弟,写点注释啊,让别人明白你想干啥啊~~~
4:英语不行吧嘿嘿,那单词太中国化了吧~~嘿嘿