Computer Science Canada How do I read till the end of a file? |
Author: | CodeMonkey2000 [ Sun Jan 20, 2008 9:12 pm ] | ||
Post subject: | How do I read till the end of a file? | ||
Suppose I am reading from a data file but I have no idea about its size. I tried doing something like this:
But it doesn't work ![]() |
Author: | HeavenAgain [ Sun Jan 20, 2008 9:15 pm ] | ||||
Post subject: | RE:How do I read till the end of a file? | ||||
|
Author: | CodeMonkey2000 [ Sun Jan 20, 2008 9:22 pm ] |
Post subject: | RE:How do I read till the end of a file? |
No, it still goes past the eof. Why doesn't this work? |
Author: | OneOffDriveByPoster [ Sun Jan 20, 2008 11:13 pm ] |
Post subject: | Re: RE:How do I read till the end of a file? |
CodeMonkey2000 @ Sun Jan 20, 2008 9:22 pm wrote: No, it still goes past the eof. Why doesn't this work? Assuming that all the file reading code is there (none in the "whatever") and that your input is of the right form, I am not quite sure why it doesn't work (may be missing something obvious though). If you did not type the input file yourself, make sure you try with something that you saved on the same machine with a reasonable text editor. If you are using DOS/Windows editors, your file may have a DOS end-of-file character that is confusing your program. |
Author: | CodeMonkey2000 [ Sun Jan 20, 2008 11:40 pm ] |
Post subject: | RE:How do I read till the end of a file? |
Never mind, I was actually dividing by zero. Strange though, my compiler kept saying that I have reached the end of file... |
Author: | md [ Mon Jan 21, 2008 1:03 am ] |
Post subject: | RE:How do I read till the end of a file? |
Compilers tell you they've reached the end of the file when there is a syntax error of some kind. Programs generate EOF errors (or more usually segfaults) when they reach the end of files. Terminology is key ![]() |