FILE结构体
typedef struct _IO_FILE FILE;
struct _IO_FILE {
int _flags;
/* High-order word is _IO_MAGIC; rest is flags. */
#define _IO_file_flags _flags
/* The following pointers correspond to the C++ streambuf protocol. */
/* Note: Tk uses the _IO_read_ptr and _IO_read_end fields directly. */
char* _IO_read_ptr;/* Current read pointer */
char* _IO_read_end;/* End of get area. */
char* _IO_read_base;/* Start of putback+get area. */
char* _IO_write_base;/* Start of put area. */
char* _IO_write_ptr;/* Current put pointer. */
char* _IO_write_end;/* End of put area. */
char* _IO_buf_base;/* Start of reserve area. */
char* _IO_buf_end;/* End of reserve area. */
/* The following fields are used to support backing up and undo. */
char *_IO_save_base; /* Pointer to start of non-current get area. */
char *_IO_backup_base; /* Pointer to first valid character of backup area */
char *_IO_save_end; /* Pointer to end of non-current get area. */
struct _IO_marker *_markers;
struct _IO_FILE *_chain;
int _fileno;
#if 0
int _blksize;
#else
int _flags2;
#endif
_IO_off_t _old_offset; /* This used to be _offset but it's too small. */
#define __HAVE_COLUMN /* temporary */
/* 1+column number of pbase(); 0 is unknown. */
unsigned short _cur_column;
signed char _vtable_offset;
char _shortbuf[1];
3.fgets
#include <stdio.h>
fgets(char* s,int size,FILE* pf1)//
描述:从pf1文件流指针所指向的文件中读取长度为size的字符串,并赋给字符串s。它会在读到EOF或者'\n'时停止。
实例:
如果一个文件的当前位置的文本如下:
Love, I Have
Since you can do it.
如果用fgets(str1,6,file1);去读取
则执行后str1 = "Love," ,读取了6-1=5个字符
这个时候再执行fgets(str1,20,file1)则执行后str1 = " I Have\n"
而如果
fgets(str1,23,file1);
则执行str1="Love ,I Have",读取了一行(包括行尾的'\n',并自动加上字符串结束符'\0'),
当前文件位置移至下一行,虽然23大于当前行上字符总和,可是不会继续到下一行。而下一
次调用 fgets()继续读取的时候是从下一行开始读。