Question regarding the End Of File operator in C

Asked By 60 points N/A Posted on -
qa-featured

I'm using Cygwin and Notepad++ on Windows 7 Ultimate to make C programs and I've just started learning C. I have a question about using the EOF operator in loops. For example if I use "  while (x!=EOF) " , what exactly is EOF ? How does the compiler know where does the file/input end? I always have to use Ctrl+Z to end my input or for EOF, how do I make EOF native to the input or file ?

SHARE
Answered By 566755 points N/A #192096

Question regarding the End Of File operator in C

qa-featured

Generally, in programming, EOF is the short term used for End Of File or end of file. It indicates the end part of a file where no more data can be read. It is also used with logical operators where a condition must be met. Checking for a file’s EOF is important when creating a program that opens and reads other files.

Depending on the programmer, EOF is often used to check where the file ends so your program knows where to append or insert additional data and then close it afterwards. The actual value of EOF depends on the system but usually is equal to -1. The use of CTRL + Z in a text file is necessary to mark the end of a text file when writing a text file.

You can create a text file directly from the command prompt without using notepad or any other text editor. You can do this using the command “copy con”. For example, type without quotes “copy con check.txt” in the command prompt then hit Enter. After that, just type any text. When you are finished, press CTRL + Z then hit Enter. This closes and saves the file check.txt.

Login/Register to Answer

Related Questions