Retro video games delivered to your door every month!
Click above to get retro games delivered to your door ever month!
X-Hacker.org- Microsoft C 6.0 - <b>ftell() get current file pointer position</b> http://www.X-Hacker.org [<<Previous Entry] [^^Up^^] [Next Entry>>] [Menu] [About The Guide]
 ftell()                 Get Current File Pointer Position

 #include   <stdio.h>

 long       ftell(stream);
 FILE       *stream;                     Pointer to FILE structure

    ftell() returns the current position of the file pointer associated
    with 'stream', measured in bytes from the beginning of the file.

    Returns:    If successful, the current pointer position; -1L on error
                and 'errno' is set to either EBADF (bad file number) or
                EINVAL (invalid argument).  An undefined value is
                returned for a device that is incapable of seeking or if
                'stream' does not refer to an open file.

      Notes:    The CR-LF translation performed for files opened in text
                mode means that the value returned by ftell() may not
                represent the correct physical offset. ftell() can,
                however, be used with fseek() to pinpoint file locations
                accurately.

   -------------------------------- Example ---------------------------------

    The following statements save the current position, move to the
    beginning of the file, then return to the saved position.

           #include <stdio.h>

           FILE *stream;
           long current_pos;

           main()
           {
               if ((stream = fopen("new.dat","rb")) != NULL) {
                   current_pos = ftell(stream);
                   fseek(stream,0L,SEEK_SET);
                   .
                   .
                   .
                   fseek(stream,current_pos,SEEK_SET);
                }
           }


See Also: fgetpos() fseek() lseek() tell()

Online resources provided by: http://www.X-Hacker.org --- NG 2 HTML conversion by Dave Pearson