Purpose

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

Header File

stdio.h
(ftell)

Prototype

long ftell (FILE * Stream);

Argument

Stream
Pointer to an open FILE structure

Return Values

>=0
Current number of bytes by which the file pointer is positioned from the origin..
-1
The seek failed.

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

See Also

lseek   Move a file pointer

External Links

ftell   HP 3000 Library Reference Manual
ftell   The Open Group Base Specifications
ftell   MSDN

Valid HTML 4.01 Transitional

Valid CSS

Site Icon Copyright © 1999-2007, jhyoung, revised 4/30/2007