Retro video games delivered to your door every month!
Click above to get retro games delivered to your door ever month!
X-Hacker.org- Turbo C - <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'.  The position is measured in bytes from the beginning
    of the file.

    Returns:    The current pointer position, if successful.  -1L is
                returned on error. An undefined value is returned on
                devices incapable of seeking, or when 'stream' does not
                refer to an open file.

      Notes:    Due to the CR-LF translation performed for files opened
                in text mode, the value returned by ftell() may not be
                the correct physical offset. ftell() can be used together
                with fseek() to correctly remember and return to file
                locations.

  -------------------------------- 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: fseek() lseek() tell()

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