C Now

FILE Stream ftell Function

Site Logo

Usage:

The ftell function is used to find the current position of a file pointer.

Prototype:

long ftell (FILE * Stream);

Argument:

Stream
Pointer to an open FILE structure.

Header Files:

stdio.h
(ftell)
errno.h
(errno values)

Returns:

>= 0
File pointer offset from the beginning of the file.
  -1
Failure.

Side Effect:

errno
Iff the ftell fails, the global variable errno is set to error code
EBADF
Handle not open

Example:

#include <stdio.h> 
 .  .  .
  FILE *    Account_Master;
  char      Buffer [100];
  int       Maximum;
  int       Actual;
  long      Pos;
    .  .  .
  Maximum = 100;
    .  .  .
  Account_Master = open ("accounts.dat", "r");
    .  .  .
  while (!eof (Account_Master)) {
    Pos = ftell (Account_Master);
    Actual = read (Account_Master, Buffer, Maximum);
    .  .  .
    fseek (Account_Master, Pos, SEEK_SET);
    Actual = fwrite (Buffer, 1, Maximum, Account_Master);
    .  .  .
  }

ftell  ftell  MSDN
C Now Home  C Now Home
Include Files Index  Include Files Index
Header stdio.h Index  Header stdio.h Index
E-Mail
Valid HTML 4.01 Transitional Valid CSS! Site Logo

copyright 2001-2006, j.h.young, revised 2/13/06

ftell /