0

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

4

1 回答 1

1

当您退出循环时,cis的值EOF不是有效的字符值(这就是它用于指示文件结尾的原因)。将其传递给putchar.

于 2013-09-06T00:46:46.793 回答