How can I detect the end of a file in C using stdio and scanf?

  • Thread starter Thread starter rocketboy
  • Start date Start date
  • Tags Tags
    File
Join the discussion
Registration is free. Start your own thread to ask a follow-up.
6 replies · 95K views
rocketboy
Messages
243
Reaction score
1
hey,

For this program I am writing in C, I am using stdio and the scanf function to detect input. Now, the person using the program commands in linux for the input to be given from a file, but the problem is I don't know how long the file is. So i have to keep scanf'ing until the file is finished.

Any ideas about how I could do this? I'm not very advanced with C.

Thanks,
-RB
 
Physics news on Phys.org
It depends on the life size also as well as what you are looking for in the file
The program can run forever till no more resource left for your computer to go on...
 


Hi , I have a question about C. I want to write program that takes numbers as inputs and orders them from maximum to minimum. However, i ve a problem .Count of number is uncertain.I mean ,sometimes i will give the program 5 numbers ,sometimes 10 numbers or another.How can i do this without using eof since i don't know using eof.Please help me ...
 
Rather than dig up a thread that is 4 1/2 years old, you should start a new thread. If this is a homework problem (and it seems to be), post it in the Homework and Coursework section, in the Engineering and Computer Science section.