End of file loop
Improve this answer. Harry Harry Pete Becker Pete Becker Example if operation! Or he could construct his loop condition so it would be false on the condition where he wants to exit the loop. He could also use goto although that would be really bad style. Use break; This will end the loop each time. SomeGuy SomeGuy 1 1 1 bronze badge. I'm not allowed to use break;. Is there another way? Greg Greg 1 2 2 bronze badges. Thank you for your answer but that would be a do while loop, wouldn't it?
I can't have that in my program. I'm stuck strictly to completing my program with a sentinel loop. JeffMann Sure. Any problems with that? The Overflow Blog. Podcast Making Agile work for data science. Stack Gives Back Featured on Meta. New post summary designs on greatest hits now, everywhere else eventually. Linked Related On Unix systems, this is control-D. The example in the book is not "wrong". It depends on what you actually want to do. Reading until EOF means that you read everything, until the user says "I'm done", and then you can't read any more.
How are we doing? Please help us improve Stack Overflow. Take our short survey. Stack Overflow for Teams — Collaborate and share knowledge with a private group. Create a free Team What is Teams?
Collectives on Stack Overflow. Learn more. Asked 11 years, 1 month ago. Active 4 years, 8 months ago. Viewed k times. Does it mean that the example on the book serves another purpose?
Improve this question. Community Bot 1 1 1 silver badge. You do understand that the book you mention is by the original authors of the C language, right? Add a comment. Active Oldest Votes. Improve this answer. Steve Jessop Steve Jessop k 34 34 gold badges silver badges bronze badges. Asked 9 years, 4 months ago.
Active 6 years, 11 months ago. Viewed k times. Improve this question. Sicco 5, 4 4 gold badges 41 41 silver badges 59 59 bronze badges. Add a comment. Active Oldest Votes. Improve this answer. In the program it is taken as i am not able to find the EOF through fscanf — karthik. What do you mean? Many people in this thread have demonstrated how to stop when fscanf returns EOF.
The answer below, the comment above When the end of the file is reached, fscanf will return EOF, which the while loop will catch, and no more stuff will be read.
In fact, you can use this to calculate your count variable. In the program it is taken as i am not able to find the EOF through fscanf. How you can do it, without a count??
0コメント