Standard Library Functions in C

adplus-dvertising
ftell() Function
Previous Home Next

Description

The C library function, The ftell() function gets the current position of the file pointer (if any) associated with stream. The position is expressed as an offset relative to the beginning of the stream.

Declaration

Following is the declaration for ftell() function.

long int ftell(FILE *stream)

Parameters

stream - A pointer to a FILE object which identifies a stream

Return Value

The ftell function returns the current file position indicator for stream. If an error occurs, the ftell function will return -1L and update errno.

Example

#include <stdio.h>

void main( void )
{
	FILE *stream;

   long position;
   char list[100];
   if( (stream = fopen( "ftell.c", "rb" )) != NULL )
   {
      /* Move the pointer by reading data: */
      fread( list, sizeof( char ), 100, stream );
      /* Get position after read: */
      position = ftell( stream );
      printf( "Position after trying to read 100 bytes: %ld\n",
              position );
      fclose( stream );
   }
}

Output

Position after trying to read 100 bytes: 100
Previous Home Next