C语言文件操作随笔

1、return 与exit的区别

     在main中return 与exit 两个返回是等效的,都是结束进程。

     但是如果二级调用中return只是返回上一级调用,但是exit表示结束进程。

2、FILE

struct _iobuf {
    char *_ptr; //文件输入的下一个位置
    int _cnt; //当前缓冲区的相对位置
    char *_base; //指基础位置(即是文件的起始位置) 
    int _flag; //文件标志
    int _file; //文件描述符id
    int _charbuf; //检查缓冲区状况,如果无缓冲区则不读取
    int _bufsiz; //文件缓冲区大小
    char *_tmpfname; //临时文件名
       };
typedef struct _iobuf FILE;
#define _FILE_DEFINED
#endif
  打开文件时,会将文件的数据读到上述结构体中,读取文件就是从缓冲区读取。当缓冲区数据读完了就再次将文件中的数据读到缓冲区,然后从缓冲区读数据。
 写文件动作相反,写到缓冲区。

 ffush

原文地址:https://www.cnblogs.com/tjyuanxi/p/9368798.html