Determining EOF using fseek()?

From: Orion (wong01_at_bigpond.net.au)
Date: 08/27/04


Date: Fri, 27 Aug 2004 14:08:23 GMT

Hey,

I was wondering if it was possible to determine if you hit 'EOF' using
fseek? I'm using fseek to traverse through the file from start to end
and capturing the data into a linked list structure. However, my loop
doesn't seem to work well - it totally fumbles out actually:

while ((a = fseek(fp,0,SEEK_CUR)) == 0){
        // code here
}

Its quite important for me not to disrupt the current position of the
cursor since I rely on that to fetch the data from the text file. I
thought that the loop would work fine since fseek only returns a
non-zero integer on an error but unfortunately this is not the case.
Anyone with suggestions with using fseek() or some other function?

Any help would be greatly appreciated! Thanks.



Relevant Pages

  • Question on EOF markers
    ... a combination of fprintf and fseek. ... loop as follows: ... fclose; clear ans fid; ... is it possible that I am somehow leaving bad EOF ...
    (comp.soft-sys.matlab)
  • Re: Determining EOF using fseek()?
    ... I'm using fseek to traverse through the file from start to end ... However, my loop ... to hold the value of EOF. ... So u can get an logical error while reading ...
    (comp.lang.c)
  • Re: Determining EOF using fseek()?
    ... > I was wondering if it was possible to determine if you hit 'EOF' using ... I'm using fseek to traverse through the file from start to end ... However, my loop ...
    (comp.lang.c)
  • Re: Determining EOF using fseek()?
    ... > I was wondering if it was possible to determine if you hit 'EOF' using ... I'm using fseek to traverse through the file from start to end ... returning the value EOF. ...
    (comp.lang.c)
  • Re: feof(), fseek(), fread()
    ... offset of a file and still be able to detect EOF?i.e. ... this without fseek(), that's why I posted this question. ... EOF is a macro defined in stdio.h probably as.. ... eoff = ftell; ...
    (comp.lang.c)