Hi, I want to use eof() function to stop reading datas from a file when it reaches to end of data. It works well except one case, which is when the file is empty. It takes a random number and make the program crashed. What can I do about that? Am I doing something wrong?
That is at line 3. The if statement is at line 1.
When you execute the if statement, you haven't yet attempted to read from the file.
Read what I quoted carefully. "flag [is] set by a previous i/o operation". You've performed no previous I/O operation.
It is not at line 3, I just wanted to show that I read the line. Do not worry about this part, I know how to read a file. As I said it works very well, but when the file is empty it crashes. What I am asking is when the file is empty.
@Cubbi sorry, I have not shared the code so everybody confused. Here is the real one. I need to use eof somehow. Project says to use it.