linux fopen函数

linux fopen函数,第1张

不是fp没有任何数据

而是当你以r方式打开文件时 FILE结构中表示开始位置或其它标志的项的值为0

如果你以a方式打开文件,再看看就不一样了

下面是/usr/include/libio.h中_IO_FILE 也就是FILE结构体的定义

struct _IO_FILE {

int _flags /* High-order word is _IO_MAGICrest 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]

/* char* _save_gptr char* _save_egptr*/

_IO_lock_t *_lock

#ifdef _IO_USE_OLD_IO_FILE

}

在/usr/include/stdio.h中可以看到有typedef struct _IO_FILE FILE

fopen函数是在当前目录下打开一个文件,其调用的一般形式为:

文件指针名=fopen(文件名,使用文件方式)

“文件指针名”必须是被声明为FILE 类型的指针变量;

“文件名”是被打开文件的文件名;

“使用文件方式”是指文件的类型和 *** 作要求;

“文件名”是字符串常量或字符数组。

例如:

FILE *fp;

fp=fopen("file a","r")

其意义是在当前目录下打开文件file a,只允许进行“读” *** 作,并使fp指向该文件。


欢迎分享,转载请注明来源:内存溢出

原文地址:https://54852.com/yw/7337618.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2023-04-04
下一篇2023-04-04

发表评论

登录后才能评论

评论列表(0条)

    保存