c.中EOF的ascii值是多少?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/7622699/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
What is the ascii value of EOF in c.?
提问by Patel Nik
Any one knows what is the ASCII value of i.
任何人都知道 i 的 ASCII 值是多少。
I try printf("%d",EOF);
我试试 printf("%d",EOF);
but its print -1
但它的印刷品 -1
and also try printf("%c",EOF);
并尝试 printf("%c",EOF);
but its print blank screen.
但它的打印空白屏幕。
so anyone know which key for EOF
.
所以任何人都知道EOF
.
回答by R.. GitHub STOP HELPING ICE
EOF
(as defined in the C language) is not a character/not an ASCII value. That's why getc
returns an int
and not an unsigned char
- because the character read could have any value in the range of unsigned char
, and the return value of getc
also needs to be able to represent the non-character valueEOF
(which is necessarily negative).
EOF
(在 C 语言中定义)不是字符/不是 ASCII 值。这就是为什么getc
返回 anint
而不是 an unsigned char
- 因为读取的字符可以具有 范围内的任何值unsigned char
,并且 的返回值getc
也需要能够表示非字符值EOF
(必然是负值)。
回答by David Heffernan
The actual value of EOF is system defined and not part of the standard.
EOF 的实际值是系统定义的,而不是标准的一部分。
EOF
is an int
with negative value and if you want to print it you should use the %d
format string. Note that this will only tell you its value on your system. You should not care what its value is.
EOF
是一个int
负值,如果你想打印它,你应该使用%d
格式字符串。请注意,这只会告诉您它在您的系统上的价值。你不应该关心它的价值是什么。
回答by daniel
there is not such thing as ascii value of EOF. There is a ASCII standard that includes 127 characters, EOF is not one of them. EOF is -1 because that's what they decided to #defined as in that particular compiler, it could be anything else.
没有 EOF 的 ascii 值这样的东西。有一个包含 127 个字符的 ASCII 标准,EOF 不是其中之一。EOF 是 -1,因为这就是他们决定在那个特定编译器中 #defined 的原因,它可以是其他任何东西。
回答by BlackBear
As Heffernan said, it's system defined. You can access it via the EOF constant (is it a constand?):
正如赫弗南所说,它是系统定义的。您可以通过 EOF 常量访问它(它是一个常量吗?):
#include <stdio.h>
int main(void)
{
printf("%d\n", EOF);
}
After compiling:
编译后:
c:\>a.exe
-1
c:\>
回答by Abdulrhman.Z
EOF do not have ASCII value as they said .... no problem with this
EOF 没有他们所说的 ASCII 值.... 没问题
also you can avoid the strange character that appear in the end (which is the numeric representation of EOF ) by making if
condition here is an example:
您也可以通过在if
此处设置条件来避免出现在最后的奇怪字符(这是 EOF 的数字表示),例如:
#include <stdio.h>
int main(void)
{
FILE *file = fopen("/home/abdulrhman/Documents/bash_history.log", "r");
FILE *file2 = fopen("/home/abdulrhman/Documents/result.txt", "w");
file =
file2 =
char hold = 'A';
while(hold != EOF)
{
hold = getc(file);
if(hold == EOF) break; // to prevent EOF from print to the stream
fputc(hold, file2);
}
fclose(file);
return 0;
}
that is it
这就对了
回答by Vineet Kapoor
EOF is not an ASCII character. Its size is not 1 byte as against size of a character and this can be checked by
EOF 不是 ASCII 字符。与字符大小相比,它的大小不是 1 个字节,可以通过以下方式检查
int main() {
printf("%lu", sizeof(EOF));
return 0;
}
However, it is always defined to be -1. Try
但是, 它始终定义为 -1。尝试
int main() {
printf("%d",EOF);
return 0;
}
The key combination for EOF is Crtl+D. The character equivalent of EOF is machine dependent. That can be checked by following:
EOF 的组合键是Crtl+ D。EOF 的字符等价物取决于机器。可以通过以下方式检查:
int main() {
printf("%c", EOF)
return 0;
}
回答by user1541890
for all intents and purposes 0x04 EOT (end of transmission as this will normaly signal and read function to stop and cut off file at that point.
出于所有意图和目的 0x04 EOT(传输结束,因为这将正常发出信号和读取功能以在该点停止和切断文件。