简单的C语言小程序题,请路过的大神帮我看看哪里错了?

输入一行字符(用回车结束),输出每个字符以及与之对应的ASCII代码值,每行输出3对
#include<stdio.h>
#include<ctype.h>
main()
{
char ch; int k;
for(;;k++)

{ while((ch=getchar())!='\n')

if(k%3==0)printf("\n");
printf("ch=%c ASCII=%d",ch,ch);

}

}

不管输什么结果都是10

while中语句应用中括号
while((ch=getchar())!='\n')

if(k%3==0)printf("\n");
printf("ch=%c ASCII=%d",ch,ch);

请采纳 谢谢
温馨提示:内容为网友见解,仅供参考
第1个回答  2014-08-08
#include<stdio.h>
#include<ctype.h>
main()
{
char ch; 
int k=0;

while((ch=getchar())!='\n')
{
    printf("ch=%c ASCII=%d",ch,ch);
    if(++k%3==0)printf("\n");
}



}

相似回答