哪些函数设置文件结束指标? [英] which functions set the end-of-file indicator?

查看:55
本文介绍了哪些函数设置文件结束指标?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,在法语C书中,作者说只有{fgetc,

getc,getchar,fgetwc,getwc,getwchar,fgets,gets,fgetws,getws,

fputc,putc,putchar,fputwc,putwc,putwchar,fputs,puts,fputws}

保证在文件结束时设置文件结束指示符达到了
,但在C99标准中,我找到了p 288(ISO / IEC 9899:TC3

委员会草案?2007年7月7日WG14 / N1256)


/ * ============================= * /

#include< ; stdio.h>

/ * ... * /

int count;浮动定量; char单位[21],item [21];

do {

count = fscanf(stdin,%f%20s of%20s"& quant,单位,项目);

fscanf(stdin,"%* [^ \ n]");

} while(!feof(stdin)&& ;!ferror(stdin));

/ * ============================= * /

似乎说fscanf系列函数设置了文件结束指标

呢?哪些函数设置了文件结束指示符?

Hi everybody, in a french C book, the author says that only {fgetc,
getc, getchar, fgetwc, getwc, getwchar, fgets, gets, fgetws, getws,
fputc, putc, putchar, fputwc, putwc, putwchar, fputs, puts, fputws}
are guaranteed to set the end-of-file indicator when the end-of-file
is reached, but in C99 standard, I find p 288 (ISO/IEC 9899:TC3
Committee Draft ? Septermber 7, 2007 WG14/N1256)

/* ============================= */
#include <stdio.h>
/* ... */
int count; float quant; char units[21], item[21];
do {
count = fscanf(stdin, "%f%20s of %20s", &quant, units, item);
fscanf(stdin,"%*[^\n]");
} while (!feof(stdin) && !ferror(stdin));
/* ============================= */
It seems to say that fscanf family function set end-of-file indicator
too? which functions set the end-of-file indicator?

推荐答案

8月4日晚上9:05,nicolas.sit ... @gmail。 com写道:

< snip>
On Aug 4, 9:05 pm, nicolas.sit...@gmail.com wrote:
<snip>

好​​像说fscanf系列函数设置文件结束指标

呢?哪些函数设置文件结束指标?
It seems to say that fscanf family function set end-of-file indicator
too? which functions set the end-of-file indicator?



执行IO操作的所有函数。 (即使perror()可以设置

如果在写入时发生错误,stderr的''错误''指示符)

All functions that perform IO operations. (ie even perror() can set
the ''error'' indicator for stderr if an error occurs at writing)




< ni ************ @ gmail.com在消息新闻中写道:

<ni************@gmail.comwrote in message news:

>大家好,在一本法语C书,作者说只有{fgetc,
getc,getchar,fgetwc,getwc,getwchar,fgets,gets,fgetws,getws,
fputc,putc,putchar,fputwc,putwc,putwchar ,fputs,puts,fputws}
保证在达到文件结尾时设置文件结束指示符。
>Hi everybody, in a french C book, the author says that only {fgetc,
getc, getchar, fgetwc, getwc, getwchar, fgets, gets, fgetws, getws,
fputc, putc, putchar, fputwc, putwc, putwchar, fputs, puts, fputws}
are guaranteed to set the end-of-file indicator when the end-of-file
is reached.



这本书是错误的,至少对所有意图和目的都是如此。在文件内容被任何

读取功能耗尽后,EOF将返回

。 feof()在第一次读取后返回true以返回EOF。


我认为他在想的是如果调用函数如fscanf()

与输入格式不匹配比你得到部分阅读 - 函数

将返回成功转换的参数数量 - 而EOF可能不会

设置,即使你非常靠近文件的末尾,也没有

完整的记录。


-

免费游戏和编程好东西。
http:// www .personal.leeds.ac.uk /~bgy1mm

The book is wrong, at least to all intents and purposes. EOF will be
returned after the contents of the file have been exhausted by any of the
read functions. feof() returns true after the first read to return EOF.

I think what he is thinking is that if a call to a function like fscanf()
doesn''t match the input format than you''ll get a partial read - the function
will return the number of arguments successfully converted - and EOF may not
be set, even if you are very close to the end of the file and have no
complete records left.

--
Free games and programming goodies.
http://www.personal.leeds.ac.uk/~bgy1mm


ni ************ @ gmail.com 写道:

嗨每个人,在法语C书中,作者说只有{fgetc,

getc,getchar,fgetwc,getwc,getwchar,fgets,gets,fgetws,getws,

fputc,putc,putchar,fpu twc,putwc,putwchar,fputs,puts,fputws}

保证在达到文件结尾
时设置文件结束指示符,但是在C99标准中,我找到了p 288(ISO / IEC 9899:TC3

委员会草案? 2007年9月7日WG14 / N1256)


/ * ============================ = * /

#include< stdio.h>

/ * ... * /

int count;浮动定量; char单位[21],item [21];

do {

count = fscanf(stdin,%f%20s of%20s"& quant,单位,项目);

fscanf(stdin,"%* [^ \ n]");

} while(!feof(stdin)&& ;!ferror(stdin));

/ * ============================= * /

似乎说fscanf系列函数设置了文件结束指标

呢?哪些函数设置文件结束指标?
Hi everybody, in a french C book, the author says that only {fgetc,
getc, getchar, fgetwc, getwc, getwchar, fgets, gets, fgetws, getws,
fputc, putc, putchar, fputwc, putwc, putwchar, fputs, puts, fputws}
are guaranteed to set the end-of-file indicator when the end-of-file
is reached, but in C99 standard, I find p 288 (ISO/IEC 9899:TC3
Committee Draft ? Septermber 7, 2007 WG14/N1256)

/* ============================= */
#include <stdio.h>
/* ... */
int count; float quant; char units[21], item[21];
do {
count = fscanf(stdin, "%f%20s of %20s", &quant, units, item);
fscanf(stdin,"%*[^\n]");
} while (!feof(stdin) && !ferror(stdin));
/* ============================= */
It seems to say that fscanf family function set end-of-file indicator
too? which functions set the end-of-file indicator?



任何尝试从流中读取的函数都可以为该流设置

文件结束指示符。 fopen(),freopen(),

clearerr(),ungetc(),fseek(),rewind()和fsetpos()函数

可以清除它(我认为这就是全部,但我可能会忽略

a少数)。没有其他函数可以修改文件结束指示符 -

除了,一如既往,如果

程序调用未定义的行为,则无法确定会发生什么。


-
呃******* **@sun.com


这篇关于哪些函数设置文件结束指标?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆