i am try to create a program that prints the numerical value of EOF...
any ideas for the function get the value of EOF using the ASCII table????

Recommended Answers

EOF doesn't have an ASCII value, it's required to be negative:

#include <stdio.h>

int main()
{
  printf("%d\n", EOF);
  return 0;
}
Jump to Post

Also pay attention: getchar(), getc(), fgetc() functions return int (not char) values.
In essence, char type in C (but not in C++) is a very short int, that's all.

Jump to Post

In essence, char type in C (but not in C++) is a very short int, that's all.

I think you will find char data type is the same in both c and c++.

Jump to Post

All 11 Replies

EOF doesn't have an ASCII value, it's required to be negative:

#include <stdio.h>

int main()
{
  printf("%d\n", EOF);
  return 0;
}

Also pay attention: getchar(), getc(), fgetc() functions return int (not char) values.
In essence, char type in C (but not in C++) is a very short int, that's all.

In essence, char type in C (but not in C++) is a very short int, that's all.

I think you will find char data type is the same in both c and c++.

In certain cases when dealing with text files or reading data from a "character device", the Microsoft MS-DOS shell (COMMAND.COM) or operating-system utility programs would historically append an ASCII control-Z character (aka the "SUB" character, 0x1A) to the end of a disk file

--source: wikipedia

Let's remember character literals in C and C++: sizeof('C') == sizeof(int) in C but it's not true in C++ (because of 'C' has int type in C but char type in C++).
See also for more subtle distinctions:
http://www.trilithium.com/johan/2005/01/char-types/

Oh I see now what you meant. I thought you meant sizeof(char) in c++ is different than in C.

Remember, EOF is macro which associated with termination of file........

What is the value of EOF in c...?

Member Avatar

if you want to end the file, then CTRL + Z, but numerical value of EOF is generally -1 .
you can check it by printing it's value using simple printf statement.

What is the value of EOF in c...?

The value of the macro EOF is completely irrelevant because it's an internal standard library flag that has no meaning to either you or the outside world. Though nitin1 is correct that it's usually defined as something like -1.

Member Avatar

yups! you don't need to care about that value, you can use it using the macro only. thanks.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of 1.20 million developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.