C EOF符号值和带符号的字符 [英] C EOF symbolic value and signed character

查看:115
本文介绍了C EOF符号值和带符号的字符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

今天,当我想到一个我无法用自己的能力解决的想法时,我只是躺在床上思考编程知识。

today i just lay on my bed meditating programming stuff when an idea flows into my mind which i can't solve with my own ability.Below is the Question.

为什么-1?通常getchar()返回一个值范围是0到127,因为这些值对应于标准字符集,但是如果系统识别扩展字符集,它可能返回0到255之间的值。在这两种情况下,值-1都不对应任何字符,因此可以用来表示文件结尾。

1。)对于上面的语句是因为我记得除了带符号的整数外,带符号的字符也是C中存在的一种变量,因此这意味着可以使用-128到127之间的值。但是为什么书中提到-1并不与任何字符使用相抵触

1.)It is weird for the statement above because i remember besides signed integer , signed character is also one type of variable exist in C , so that's mean the value from -128 to 127 can be used.But why still the book mention -1 does not contradict to any character use for keyboard input??

推荐答案

标准不是说它是 -1


EOF 扩展为一个整数常量表达式,类型为int和
a负值,它由多个函数返回以指示
文件结束,即不再有来自流的输入

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

这不是您可以从文件中读取的值。 getc 是带外值,在文件结束以外的任何情况下都不会返回。

It's not a value that you can read from a file. It's an "out of band" value that getc and such can't return in any case other than "end of file".

这篇关于C EOF符号值和带符号的字符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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