数据文件的问题 [英] problem with Data Files

查看:71
本文介绍了数据文件的问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,

当我尝试从文件中输入一个字符时会发生什么

已完成,换句话说''c'包含什么'在执行以下代码中的最后一个

语句之后:


FILE * file = fopen(" FILE1.c"," r");

char c;

while((c = fgetc(file))!= EOF);

c = fgetc(file);

//现在c的值是多少?????????????????

谢谢,

Alice

hi all,
What will happen when I tries to input a character from a file
which is finished, in other words what will ''c'' contains after the last
statement in the following code is executed :

FILE * file =fopen("FILE1.c","r");
char c;
while((c=fgetc(file)) != EOF);
c=fgetc(file);
// what is value of c now???????????????????
Thanks,
Alice

推荐答案

2005年1月18日星期二09:38:54 -0800,alice写道:
On Tue, 18 Jan 2005 09:38:54 -0800, alice wrote:
大家好,
当我尝试从文件中输入一个完成的字符时会发生什么,换句话说,在最后一个文件中包含什么''c''执行以下代码中的语句:

FILE * file = fopen(" FILE1.c"," r");
char c;
while( (c = fgetc(file))!= EOF);


这是不正确的,c需要定义为int。 fgetc()返回int和

EOF不能保证可以表示为char。如果不是它不会与所有可能的char值区别开来。

c = fgetc(文件);
//现在c的值是多少???????????????????谢谢,
hi all,
What will happen when I tries to input a character from a file
which is finished, in other words what will ''c'' contains after the last
statement in the following code is executed :

FILE * file =fopen("FILE1.c","r");
char c;
while((c=fgetc(file)) != EOF);
This is incorrect, c needs to be defined as int. fgetc() returns int and
EOF is not guaranteed to be representable as a char. If it is it won''t be
distinct from all possible char values.
c=fgetc(file);
// what is value of c now??????????????????? Thanks,




可能再次EOF,如果在此期间文件结束条件

被清除,可能还有其他内容。文件结束条件可能很粘,但它不是必须的b $ b。如果您想在

指示文件结束后再尝试进行文件I / O,则应该执行文件搜索操作,如果

合适,或者调用clearerr( )。你不应该只是尝试另外的阅读操作。


劳伦斯



Probably EOF again, maybe something else if the end-of-file condition
cleared in the meantime. End-of-file condition can be sticky but it
doesn''t have to be. If you want to attempt further file I/O after
end-of-file is indicated you should perform a file seek operation if that
is appropriate or else call clearerr(). You should not simply attempt
another read operation.

Lawrence


EOF(-1)

EOF (-1)


" bhanu" <去*********** @ hotmail.com>写道:
"bhanu" <go***********@hotmail.com> writes:
EOF(-1)




EOF通常为-1,但不保证该值。 EOF可以是任何

负'int''值。

-

int main(void){char p [] =" ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuv wxyz。\

\ n",* q =" kl BIcNBFr.NKEzjwCIxNJC" ;; int i = sizeof p / 2; char * strchr(); int putchar(\

); while(* q){i + = strchr(p,* q ++) - p; if(i> =(int)sizeof p)i- = sizeof p-1; putchar(p [i ] \

);}返回0;}



EOF is often -1 but that value is not guaranteed. EOF may be any
negative `int'' value.
--
int main(void){char p[]="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuv wxyz.\
\n",*q="kl BIcNBFr.NKEzjwCIxNJC";int i=sizeof p/2;char *strchr();int putchar(\
);while(*q){i+=strchr(p,*q++)-p;if(i>=(int)sizeof p)i-=sizeof p-1;putchar(p[i]\
);}return 0;}


这篇关于数据文件的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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