是EOF总是消极的? [英] Is EOF always negative?
问题描述
时的EOF总是消极的?
我想编写一个函数,在输入读取下一个单词并返回字或EOF被发现,如果输入的结尾已经达到了行号。如果EOF不一定是负面的,作用是不正确的。
是的,EOF总是负的。
标准说:
7.19输入/输出
7.19.1简介
3的宏[...]这EOF
扩展为一个整型常量
前pression,int型的和
负值,由返回
几个功能指示
结束文件,也就是,没有更多的输入
从流;
块引用>请注意,有与普通
字符
签字没有问题。在< stdio.h中>
这对付字符
职能,特别是投的字符unsigned char型
再到INT
,让所有有效字符有积极的价值。例如:INT龟etc(FILE *流)
7.19.7.1
...在龟etc功能获得该字符为unsigned char转换为int ...
块引用>Is EOF always negative?
I'm thinking of writing a function that reads the next word in the input and returns the line number the word was found in or EOF if the end of the input has been reached. If EOF is not necessarily negative, the function would be incorrect.
解决方案Yes, EOF is always negative.
The Standard says:
7.19 Input/output
7.19.1 Introduction3 The macros are [...] EOF which expands to an integer constant expression, with type int and a negative value, that is returned by several functions to indicate end-of-file, that is, no more input from a stream;
Note that there's no problem with "plain"
char
being signed. The<stdio.h>
functions which deal withchar
s, specifically cast the characters tounsigned char
and then toint
, so that all valid characters have a positive value. For example:int fgetc(FILE *stream)
7.19.7.1
... the fgetc function obtains that character as an unsigned char converted to an int ...
这篇关于是EOF总是消极的?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!