c语言中C文件如何变成c_file文件

Python011

c语言中C文件如何变成c_file文件,第1张

数据先送到缓冲区,再传给C语言程序或则外存上,缓冲文件系统利用文件指针标识文件。

FILE是在stdio.h中定义的结构体类型,封装了与文件有关的信息,如文件句柄、位置指针及缓冲区等,缓冲文件系统为每个被使用的文件在内存中开辟一个缓冲区。

c语言中file

vc中

在"stdio.h"中有如下定义

struct

_iobuf

{

char

*_ptr

//文件输入的下一个位置

int

_cnt

//当前缓冲区的相对位置

char

*_base

//指基础位置(即是文件的其始位置)

int

_flag

//文件标志

int

_file

//文件的有效性验证

int

_charbuf

//检查缓冲区状况,如果无缓冲区则不读取

int

_bufsiz

//缓冲区的大小

char

*_tmpfname

//临时文件名

}

typedef

struct

_iobuf

file。

不能用全局变量的话,只能用指针传递.以下是例子.

首先要在工程目录下建立文件g.dat

#include

<stdio.h>

void

fun1(FILE

*p)

{

fwrite("11",2,2,p)

}

void

fun2(FILE

*p)

{

fwrite("22",2,2,p)

}

int

main()

{

FILE

*p1

=

NULL

p1

=

fopen("g.dat","rw")

fun1(p1)

fun2(p1)

fclose(p1)

return

0

}