以文件结束结尾是什么意思

balabalaxi~ 2015-01-30 09:24:01
有些编程题目会写:测试数据有多组,以文件结尾。请问应该如何使用测试数据?什么叫以文件结束结尾。
...全文
785 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
蜥蜴枪王 2015-01-31
  • 打赏
  • 举报
回复
就是指读到文件末尾,有预定义常量EOF来标识。
赵4老师 2015-01-30
  • 打赏
  • 举报
回复
fscanf, fwscanf Read formatted data from a stream. int fscanf( FILE *stream, const char *format [, argument ]... ); int fwscanf( FILE *stream, const wchar_t *format [, argument ]... ); Function Required Header Compatibility fscanf <stdio.h> ANSI, Win 95, Win NT fwscanf <stdio.h> or <wchar.h> ANSI, Win 95, Win NT For additional compatibility information, see Compatibility in the Introduction. Libraries LIBC.LIB Single thread static library, retail version LIBCMT.LIB Multithread static library, retail version MSVCRT.LIB Import library for MSVCRT.DLL, retail version Return Value Each of these functions returns the number of fields successfully converted and assigned; the return value does not include fields that were read but not assigned. A return value of 0 indicates that no fields were assigned. If an error occurs, or if the end of the file stream is reached before the first conversion, the return value is EOF for fscanf or WEOF for fwscanf. Parameters stream Pointer to FILE structure format Format-control string argument Optional arguments Remarks The fscanf function reads data from the current position of stream into the locations given by argument (if any). Each argument must be a pointer to a variable of a type that corresponds to a type specifier in format. format controls the interpretation of the input fields and has the same form and function as the format argument for scanf; see scanf for a description of format. If copying takes place between strings that overlap, the behavior is undefined. fwscanf is a wide-character version of fscanf; the format argument to fwscanf is a wide-character string. These functions behave identically otherwise. Generic-Text Routine Mappings TCHAR.H Routine _UNICODE & _MBCS Not Defined _MBCS Defined _UNICODE Defined _ftscanf fscanf fscanf fwscanf For more information, see Format Specification Fields – scanf functions and wscanf Functions. Example /* FSCANF.C: This program writes formatted * data to a file. It then uses fscanf to * read the various data back from the file. */ #include <stdio.h> FILE *stream; void main( void ) { long l; float fp; char s[81]; char c; stream = fopen( "fscanf.out", "w+" ); if( stream == NULL ) printf( "The file fscanf.out was not opened\n" ); else { fprintf( stream, "%s %ld %f%c", "a-string", 65000, 3.14159, 'x' ); /* Set pointer to beginning of file: */ fseek( stream, 0L, SEEK_SET ); /* Read data back from file: */ fscanf( stream, "%s", s ); fscanf( stream, "%ld", &l ); fscanf( stream, "%f", &fp ); fscanf( stream, "%c", &c ); /* Output data read: */ printf( "%s\n", s ); printf( "%ld\n", l ); printf( "%f\n", fp ); printf( "%c\n", c ); fclose( stream ); } } Output a-string 65000 3.141590 x Stream I/O Routines See Also _cscanf, fprintf, scanf, sscanf
nashse 2015-01-30
  • 打赏
  • 举报
回复
正解。补充:一般情况下,EOF解释为-1(也有例外),EOF用于文本文件(ASCLL文件)结尾。由于字符的ASCII码不可能出现-1,因此EOF定义为-1是合适的。当读入的字符值等于EOF时,表示读入的已不是正常的字符而是文件结束符,但这适用对文本文件的读写。
引用 3 楼 OrthocenterChocolate 的回复:
意思就是以EOF结尾,EOF是一个已经定义好的常量,用来标识文件的结尾,当读到这个符号时,程序就知道已经读完了。
勤奋的小游侠 2015-01-30
  • 打赏
  • 举报
回复
如果你一个字符一个字符去读取一个文件,会返回各个字符值,当遇到文件结尾时,则会返回一个eof(end of file)值来表明文件结束。 通常eof是一个预定义好的宏,是一个特殊的整数。
Kenney_Qin 2015-01-30
  • 打赏
  • 举报
回复
意思就是以EOF结尾,EOF是一个已经定义好的常量,用来标识文件的结尾,当读到这个符号时,程序就知道已经读完了。
Saleayas 2015-01-30
  • 打赏
  • 举报
回复
Ctrl-Z
sprawling 2015-01-30
  • 打赏
  • 举报
回复
文件结束就是EOF符号啊.

64,648

社区成员

发帖
与我相关
我的任务
社区描述
C++ 语言相关问题讨论,技术干货分享,前沿动态等
c++ 技术论坛(原bbs)
社区管理员
  • C++ 语言社区
  • encoderlee
  • paschen
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
  1. 请不要发布与C++技术无关的贴子
  2. 请不要发布与技术无关的招聘、广告的帖子
  3. 请尽可能的描述清楚你的问题,如果涉及到代码请尽可能的格式化一下

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