jessica权宁一承认:输入一行字符,分别统计出其中英文字母、空格、数字和其它字符的个数。

来源:百度文库 编辑:高校问答 时间:2024/04/30 01:12:03
我的代码错在哪啦。。。。
#include <stdio.h>
main()
{
char c;
int letter=0,space=0,digit=0,others=0;
printf("please input some characters\n");
while((c=getchar())!="\n")
{if(c>='a'%%c<='z'||c>='A'&&c<='Z')
letter++;
else if(c==' ')
space++;
else if(c>='0'&&c<='9')
digit++;
else
others++;
}
printf("all in all:letter=%d space=%d digit=%d others=%d\n",letter,space,digit,others);
getch();
}
thank可是我想结束输入应该怎么结束呢?
回车不好用啊
按ctrl+z只出现^Z符号啊

if(c>='a'%%c<='z'||c>='A'&&c<='Z'
%%应该是&&吧?
((c=getchar())!="\n" 这个一直成立
该成!='\0'试试,不记得换行是啥了

按Ctrl+Z强行结束输入