putchar(c)这里'_'的价值是多少?

时间:2013-09-06 00:39:10

标签: c printf putchar kr-c

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)空间的价值吗?

1 个答案:

答案 0 :(得分:1)

退出循环时,c的值为EOF,这不是有效的字符值(这就是它用于表示文件结尾的原因)。将它传递给putchar是没有意义的。