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.
It is not working again, program does not enter the if statement. There should be something that checks if the file is empty or not? EOF does not do it.
By the way, I said earlier I need to use eof. I used already in while loop, this if statement is for only if the file is empty or not. So, is there any other way, I can use it. Not just eof.