Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the ascii value of EOF in c.?

Tags:

c++

c

Any one knows what is the ASCII value of i.

I try printf("%d",EOF);

but its print -1

and also try printf("%c",EOF);

but its print blank screen.

so anyone know which key for EOF.

like image 602
Patel Nik Avatar asked Oct 01 '11 20:10

Patel Nik


People also ask

What is ASCII value of EOF?

The ascii value for EOF (CTRL-D) is 0x05 as shown in this ascii table . Typically a text file will have text and a bunch of whitespaces (e.g., blanks, tabs, spaces, newline characters) and terminate with an EOF.

What is EOF and its value in C?

EOF instead is a negative integer constant that indicates the end of a stream; often it's -1, but the standard doesn't say anything about its actual value. C & C++ differ in the type of NULL and '\0' : in C++ '\0' is a char , while in C it's an int ; this because in C all character literals are considered int s.

How do I code EOF?

On Linux systems and OS X, the character to input to cause an EOF is Ctrl - D . For Windows, it's Ctrl - Z .

What datatype is EOF?

In computing, end-of-file (EOF) is a condition in a computer operating system where no more data can be read from a data source. The data source is usually called a file or stream.


3 Answers

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 value EOF (which is necessarily negative).

like image 71
R.. GitHub STOP HELPING ICE Avatar answered Oct 03 '22 17:10

R.. GitHub STOP HELPING ICE


The actual value of EOF is system defined and not part of the standard.

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.

like image 38
David Heffernan Avatar answered Oct 03 '22 17:10

David Heffernan


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.

like image 37
daniel Avatar answered Oct 03 '22 19:10

daniel