fopen?

elevenj 2002-06-26 05:29:30
FILE *fpInput=NULL;
FILE *fpOutput=NULL;
fpInput=fopen("rng_in.txt","r");
fpOutput=fopen("rng_out.txt","w");
谁能帮忙解释一下fopen的操作,及结果。
...全文
525 点赞 收藏 8
写回复
8 条回复
切换为时间正序
当前发帖距今超过3年,不再开放新的回复
发表回复
elevenj 2002-06-28
up ,再次up
回复
elevenj 2002-06-28
你这不是起哄吗?
回复
fangrk 2002-06-28
多看帮助啊!要学会自学
回复
hurrah_yule 2002-06-27
up
回复
elevenj 2002-06-27
up,没办法,只好自己up了
回复
elevenj 2002-06-27
那些相关方法操作这类指针,处理文件
回复
richard_hu 2002-06-26
fopen就是根据第二个参数来决定对第一个参数所指定的文件作什么操作,是读,还是写,还是创建,等等。返回值为一个指向FILE结构的指针。我们接下来所有的操作都是对这个指针进行的。
回复
fangrk 2002-06-26
Syntax

#include <stdio.h>
FILE *fopen(const char *filename, const char *mode);
FILE *_wfopen(const wchar_t *filename, const wchar_t *mode);

Description

Opens a stream.

fopen opens the file named by filename and associates a stream with it. fopen returns a pointer to be used to identify the stream in subsequent operations.

The mode string used in calls to fopen is one of the following values:

Value Description

r Open for reading only.

w Create for writing. If a file by that name already exists, it will be overwritten.

a Append; open for writing at end-of-file or create for writing if the file does not exist.

r+ Open an existing file for update (reading and writing).

w+ Create a new file for update (reading and writing). If a file by that name already exists, it will be overwritten.

a+ Open for append; open (or create if the file does not exist) for update at the end of the file.


To specify that a given file is being opened or created in text mode append a t to the mode string (rt w+t and so on). Similarly to specify binary mode append a b to the mode string (wb a+b and so on). fopen also allows the t or b to be inserted between the letter and the + character in the mode string; for example rt+ is equivalent to r+t.

If a t or b is not given in the mode string the mode is governed by the global variable _fmode. If _fmode is set to O_BINARY files are opened in binary mode. If _fmode is set to O_TEXT they are opened in text mode. These O_... constants are defined in fcntl.h.

When a file is opened for update, both input and output can be done on the resulting stream; however,

output cannot be directly followed by input without an intervening fseek or rewind
input cannot be directly followed by output without an intervening fseek, rewind, or an input that encounters end-offile

Return Value

On successful completion fopen returns a pointer to the newly opened stream. In the event of error it returns NULL.
回复
发动态
发帖子
C语言
创建于2007-09-28

6.3w+

社区成员

C语言相关问题讨论
申请成为版主
社区公告
暂无公告