文件尾存在EOF吗?

参考:http://bbs.csdn.net/topics/290027166

我們先一起來看看FILE是怎么定義的:
  FILE                          <STDIO.H>

File control structure for streams.

  typedef struct {
    short          level;
    unsigned       flags;    char           fd;
    unsigned char  hold;
    short          bsize;
    unsigned char *buffer, *curp;
    unsigned       istemp;
    short          token;
  } FILE;

再來看看這個flags是怎么定義的:
  _F_xxxx                           <STDIO.H>

File status flags of streams

  Name    ?Meaning
  _F_RDWR ?Read and write
  _F_READ ?Read-only file
  _F_WRIT ?Write-only file
  _F_BUF  ?Malloc'ed buffer data
  _F_LBUF ?Line-buffered file
  _F_ERR  ?Error indicator
  _F_EOF  ?EOF indicator
  _F_BIN  ?Binary file indicator
  _F_IN   ?Data is incoming
  _F_OUT  ?Data is outgoing
  _F_TERM ?File is a terminal
}

在來看看EOF在頭文件中是怎么定義的:
/*EOF a constant indicating that the end-of-file has been reached on a file*/

#define _F_EOF  0x0020                  /* EOF indicator        */
#define EOF     (-1)                    /* End of file indicator */
EOF在與fread等文件函數的返回值做比較時,時替換為(-1)的
在文件中根本不存在EOF這個東西,EOF不過是文件類函數讀到結尾時返回的一個結束標志

 

另外,在谭浩强版C语言教程中也有说明:EOF是在stdio.h文件中定义的符号常量,值为-1。......如果在执行fgetc函数读字符时遇到文件结束符,函数返回一个文件结束标志EOF(即-1)。

转载于:https://www.cnblogs.com/nufangrensheng/p/3491718.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值