ftell

Returns the current read/write position of a stream

Local Servers:nonblocking
Remote Servers:nonblocking
Classification:ANSI
Platform:NLM
Service:Stream I/O

Syntax

  #include <stdio.h>  
   
  long int ftell  (  
     FILE   *fp);
  

Parameters

fp
(IN) Points to the file.

Return Values

The ftell function returns the current read/write position of the file specified by fp. When an error is detected, a value of -1 is returned. If an error occurs, errno is set.

Remarks

The ftell function returns the current read/write position of the file specified by fp. This position defines the character to be read or written by the next I/O operation on the file. You can use the value returned by ftell in a subsequent call to fseek in order to set the file to the same position.

See Also

fgetpos, fopen, fseek, fsetpos

ftell Example

You can determine the size of a file by using the following example, which saves and restores the current position of the file.

  #include <stdio.h> 
    
  long int   filesize (FILE *fp)  
   
  {  
     long int    save_pos, size_of_file;  
     save_pos = ftell (fp);  
     fseek ( fp, 0L, SEEK_END);  
     size_of_file = ftell (fp);  
     fseek (fp, save_pos, SEEK_SET);  
     return (size_of_file);  
  }