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的操作,及结果。
...全文
577 8 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
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.

70,023

社区成员

发帖
与我相关
我的任务
社区描述
C语言相关问题讨论
社区管理员
  • C语言
  • 花神庙码农
  • 架构师李肯
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧