C语言惊天大问题,不是高手别来忽悠我。简单的统计空格换行符制表符也能出现的问题!

#include<stdio.h>
main()
{char c;
char endflag='#';
int a,b,d;
a=0,b=0,d=0;
while((c=getchar())!=endflag)
{if(c==' ') ++a;
if(c=='\d') ++b;
if(c=='\t') ++d;
}printf("%3d%3d%3d\n",a,b,d);
return 0;
}
输入一串字符进去后,我觉得有个疑问,为什么明明enter换行了缺显示换行符0?哪里出问题了?

你看看你程序,还要高手来,你好菜。换行符是\d吗,你改为\n试试行不
源程序如下:
#include<stdio.h>
void main()
{
char c;
char endflag='#';
int a,b,d;
a=0,b=0,d=0;
while((c=getchar())!=endflag)
{
if(c==' ')a++;//这里我改为了a++
if(c=='\n')b++;//..
if(c=='\t')d++;//..
}
printf("%3d%3d%3d\n",a,b,d);
return 0;
}
温馨提示:答案为网友推荐,仅供参考
第1个回答  2013-01-31
你的程序没有统计换行符啊 “\d”是退格,换行回车是“\r\n”
第2个回答  2013-01-31
这个问题很简单,(我不是高手)if(c=='\d') ++b;\d应该改成\n,换行是\n,而不是\d
第3个回答  2013-01-31
if(c=='\n') ++b; 换行符是\n
第4个回答  2013-01-31
额可能我真的是菜鸟我真的不知道'\d'是什么意思'
相似回答
大家正在搜