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);
              }
          }

Seealso:



This page last updated on Fri Nov 30 10:48:32 MSK 2001
Copyright © 1992-2001, Vitaly Filatov, Moscow, Russia
Webmaster