Chinaunix首页 | 论坛 | 博客
  • 博客访问: 547818
  • 博文数量: 179
  • 博客积分: 3845
  • 博客等级: 中校
  • 技术积分: 2003
  • 用 户 组: 普通用户
  • 注册时间: 2010-08-16 21:25
文章分类
文章存档

2012年(74)

2011年(105)

分类: C/C++

2011-04-25 21:00:07

C语言程序设计中有这么一段程序:
#include

/*用于将输入复制到输出的程序;*/
main()
{

        int c;

        while( (c = getchar()) != EOF)
                putchar(c);

}
那么从键盘输入什么的时候字符C才等于EOF呢?

/* This program prompts for input, and then captures a character
 * from the keyboard. If EOF is signalled (typically through a
 * control-D or control-Z character, though not necessarily),
 * the program prints 0. Otherwise, it prints 1.
 *
 * If your input stream is buffered (and it probably is), then
 * you will need to press the ENTER key before the program will
 * respond.
 */
 
#include
 
int main(void)
{
  printf("Press a key. ENTER would be nice :-)\n\n");
  printf("The expression getchar() != EOF evaluates to %d\n", getchar() != EOF);
  return 0;
}

由以上可知输入control-D时,C ==  EOF!
那么EOF的值又是多少呢?

/*Write a program to print the value of EOF .*/
#include
 int main(void)
{
  printf("The value of EOF is %d\n\n", EOF);
 
  return 0;
}
由以上程序结果可知EOF = -1 。

阅读(1506) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~