Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

Detecting end of file (C)

  1. Oct 2, 2006 #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
     
  2. jcsd
  3. Oct 2, 2006 #2

    Dr Transport

    User Avatar
    Science Advisor
    Gold Member

    use a while loop and look for the end of file character (EOF)

    while (!EOF)
    {
    scanf();
    }
     
  4. Oct 2, 2006 #3
    its beautiful.

    thanks dr t.
     
  5. Oct 3, 2006 #4
    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...
     
  6. Mar 19, 2011 #5
    Re: detecting inputs in C

    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 dont know using eof.Please help me ...
     
  7. Mar 19, 2011 #6
    By the way I use linux
     
  8. Mar 20, 2011 #7

    Mark44

    Staff: Mentor

    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.
     
Know someone interested in this topic? Share this thread via Reddit, Google+, Twitter, or Facebook

Have something to add?



Similar Discussions: Detecting end of file (C)
  1. C++ file i/o (Replies: 7)

  2. C++ csv file reading (Replies: 2)

Loading...