| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 669 人关注过本帖
标题:这个程序的FILE如何创建
只看楼主 加入收藏
wshingdc
Rank: 1
等 级:新手上路
帖 子:40
专家分:0
注 册:2006-3-30
收藏
 问题点数:0 回复次数:5 
这个程序的FILE如何创建

tn7TLqF0.txt (2.49 KB) 这个程序的FILE如何创建


里面的scanner函数调用的FILE 类型的变量怎么创建啊
可以指定具体的路径吗

[此贴子已经被作者于2006-9-29 11:30:59编辑过]

搜索更多相关主题的帖子: FILE 
2006-09-29 11:29
wfpb
Rank: 6Rank: 6
等 级:贵宾
威 望:29
帖 子:2188
专家分:0
注 册:2006-4-2
收藏
得分:0 

void main(){
FILE *f=fopen(文件,打开方式)。
scanner(f);
}


[glow=255,red,2]wfpb的部落格[/glow] 学习成为生活的重要组成部分!
2006-09-29 11:44
wfpb
Rank: 6Rank: 6
等 级:贵宾
威 望:29
帖 子:2188
专家分:0
注 册:2006-4-2
收藏
得分:0 
要记得close

[此贴子已经被作者于2006-9-29 11:45:32编辑过]



[glow=255,red,2]wfpb的部落格[/glow] 学习成为生活的重要组成部分!
2006-09-29 11:45
wshingdc
Rank: 1
等 级:新手上路
帖 子:40
专家分:0
注 册:2006-3-30
收藏
得分:0 

谢谢 我去试下


什么都不能加啊!!
2006-09-29 15:11
wshingdc
Rank: 1
等 级:新手上路
帖 子:40
专家分:0
注 册:2006-3-30
收藏
得分:0 
可惜 我还是没弄懂
我要打开的文件是在 D:\Program Files\Microsoft Visual Studio\MyProjects\compider\test.txt
这个路径下的哪个test.txt文件
FILE *f=fopen(文件,打开方式);
里面的 文件,和打开方式要怎么写


什么都不能加啊!!
2006-09-29 15:20
wfpb
Rank: 6Rank: 6
等 级:贵宾
威 望:29
帖 子:2188
专家分:0
注 册:2006-4-2
收藏
得分:0 

程序代码:

The character string mode specifies the type of access requested for the file, as follows:

\"r\"
Opens for reading. If the file does not exist or cannot be found, the fopen call fails.
\"w\"
Opens an empty file for writing. If the given file exists, its contents are destroyed.
\"a\"
Opens for writing at the end of the file (appending) without removing the EOF marker before writing new data to the file; creates the file first if it doesn’t exist.
\"r+\"
Opens for both reading and writing. (The file must exist.)
\"w+\"
Opens an empty file for both reading and writing. If the given file exists, its contents are destroyed.
\"a+\"
Opens for reading and appending; the appending operation includes the removal of the EOF marker before new data is written to the file and the EOF marker is restored after writing is complete; creates the file first if it doesn’t exist.
When a file is opened with the \"a\" or \"a+\" access type, all write operations occur at the end of the file. The file pointer can be repositioned using fseek, but is always moved back to the end of the file before any write operation is carried out. Thus, existing data cannot be overwritten.

The \"a\" mode does not remove the EOF marker before appending to the file. After appending has occurred, the MS-DOS TYPE command only shows data up to the original EOF marker and not any data appended to the file. The \"a+\" mode does remove the EOF marker before appending to the file. After appending, the MS-DOS TYPE command shows all data in the file. The \"a+\" mode is required for appending to a stream file that is terminated with the CTRL+Z EOF marker.

When the \"r+\", \"w+\", or \"a+\" access type is specified, both reading and writing are allowed (the file is said to be open for “update”). However, when you switch between reading and writing, there must be an intervening fflush, fsetpos, or fseek operation. The current position can be specified for the fsetpos or fseek operation, if desired.

In addition to the above values, the following characters can be included in mode to specify the translation mode for newline characters:

t
Open in text (translated) mode. In this mode, CTRL+Z is interpreted as an end-of-file character on input. In files opened for reading/writing with \"a+\", fopen checks for a CTRL+Z at the end of the file and removes it, if possible. This is done because using fseek and ftell to move within a file that ends with a CTRL+Z, may cause fseek to behave improperly near the end of the file.
Also, in text mode, carriage return–linefeed combinations are translated into single linefeeds on input, and linefeed characters are translated to carriage return–linefeed combinations on output. When a Unicode stream-I/O function operates in text mode (the default), the source or destination stream is assumed to be a sequence of multibyte characters. Therefore, the Unicode stream-input functions convert multibyte characters to wide characters. For the same reason, the Unicode stream-output functions convert wide characters to multibyte characters.

b
Open in binary (untranslated) mode; translations involving carriage-return and linefeed characters are suppressed.
If t or b is not given in mode, the default translation mode is defined by the global variable _fmode. If t or b is prefixed to the argument, the function fails and returns NULL.

For more information about using text and binary modes in Unicode and multibyte stream-I/O, see Text and Binary Mode File I/O and Unicode Stream I/O in Text and Binary Modes.

c
Enable the commit flag for the associated filename so that the contents of the file buffer are written directly to disk if either fflush or _flushall is called.
n
Reset the commit flag for the associated filename to “no-commit.” This is the default.
Example
/* FOPEN.C: This program opens files named \"data\"
* and \"data2\".It uses fclose to close \"data\" and
* _fcloseall to close all remaining files.
*/

#include <stdio.h>

FILE *stream, *stream2;

void main( void )
{
int numclosed;

/* Open for read (will fail if file \"data\" does not exist) */
if( (stream = fopen( \"data\", \"r\" )) == NULL )
printf( \"The file 'data' was not opened\n\" );
else
printf( \"The file 'data' was opened\n\" );

/* Open for write */
if( (stream2 = fopen( \"data2\", \"w+\" )) == NULL )
printf( \"The file 'data2' was not opened\n\" );
else
printf( \"The file 'data2' was opened\n\" );

/* Close stream */
if( fclose( stream ) )
printf( \"The file 'data' was not closed\n\" );

/* All other files are closed: */
numclosed = _fcloseall( );
printf( \"Number of files closed by _fcloseall: %u\n\", numclosed );
}

Output
The file 'data' was opened
The file 'data2' was opened
Number of files closed by _fcloseall: 1



[glow=255,red,2]wfpb的部落格[/glow] 学习成为生活的重要组成部分!
2006-09-29 17:00
快速回复:这个程序的FILE如何创建
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.036886 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved