putchar(c)外循环的价值是什么?
main()
{
int c;
while (c = getchar() != EOF) {
printf("printf c_inloop :%d\n",c);
printf("Putchar c_inside: ");
putchar(c);
printf("\n\n");
}
putchar(c);
printf("printf c_outloop %d",c); /*outside loop*/
}
当我运行程序时,说出“th”(wtq)并在cmd中按Enter键(Windows):
th
printf c_inloop :1
Putchar c_inside:(gives me a smileyface emoticon)
printf c_inloop :1
Putchar c_inside:(gives me a smileyface emoticon)
printf c_inloop :1
Putchar c_inside:(gives me a smileyface emoticon)
^Z (Ctrl + Z)
printf c_outloop 0
请注意printf c_outloop 0
之前的空格。是putchar(c)
空间的价值吗?
答案 0 :(得分:1)
退出循环时,c
的值为EOF
,这不是有效的字符值(这就是它用于表示文件结尾的原因)。将它传递给putchar
是没有意义的。