N/APosted on - 11/14/2014
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 ?
Question regarding the End Of File operator in C
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.