End of file marker / file scans?

EOF is a constant defined in stdio. H usually as -1. That's the reason that the first one happens to work for you.

However, it's bad practice to use the literal -1 as an implementation can theoretically define EOF however it wants. So you really want to do something along the lines of while ( fscanf(point, "%d", &number)! = EOF ).

EOF is a constant defined in stdio. H usually as -1. That's the reason that the first one happens to work for you.

However, it's bad practice to use the literal -1 as an implementation can theoretically define EOF however it wants. So you really want to do something along the lines of while ( fscanf(point, "%d", &number)! = EOF ) See the fscanf man page: kernel.org/doc/man-pages/online/pages/ma....

No, these two are not the same: while ( fscanf(point, "%d", &number)! = -1) while (!feof(point) ) fscanf can return EOF (which you should be using rather than -1) for multiple reasons: If the input ends before the first matching failure or conversion, EOF shall be returned. If any error occurs, EOF shall be returned, and errno shall be set to indicate the error.

But feof: The feof() function shall return non-zero if and only if the end-of-file indicator is set for stream.

The first statement: while ( fscanf(point, "%d", &number)! = -1) will ultimately consume the contents of your file (when fscanf returns -1 in most cases, which is EOF) while: while (!feof(point) ) will just give you and endless loop since feof just checks if it is the end of file. You need to have something to make your file position pointer move forward.

While ( point! = EOF) will give you and error since point is a pointer to a FILE structure while EOF is an int (as far as EOF is defined most of the time).

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions