ftell()

The ftell function obtains the current value of the file position indicator for the stream pointed to by f.

Synopsis

long ftell( file f);

Parameter

Parameter Description
f File with the wanted position. You can specify an absolute path or a relative path from the PROJ_PATH directory.

Return value

In the event of errors, the function returns -1 or EOF otherwise, a position in bytes.

Error

If incorrect data types are used or if a file is not open.

Description

The ftell() function obtains the current value of the file position indicator for the stream pointed to by f.

Example

The following example opens a file, obtains the position of the pointer and sets the position to different

values:

main()
{
  long tell, seek, offset, whence;
  file f;
  string dat, mod;
  f=fopen("C:/TEMP/Abb.txt", "r+"); // Open file
  // tell at the begin to 0
  tell=ftell(f);
  DebugN(tell); // 0
  // set pointer to 30
  seek=fseek(f, 30, SEEK_SET);
  tell=ftell(f);
  DebugN(tell);// 30
  // set pointer to 30 from the current position
  seek=fseek(f, 30, SEEK_CUR);
  tell=ftell(f);
  DebugN(tell); // 60
  // set pointer to the end + 60
  seek=fseek(f, 60, SEEK_END);
  tell=ftell(f);
  DebugN(tell); // 8224
  // set pointer to the end
  seek=fseek(f, 0, SEEK_END);
  tell=ftell(f);
  DebugN(tell); //8164
  // set pointer again to end + 60
  seek=fseek(f, 60, SEEK_CUR);
  tell=ftell(f);
  DebugN(tell); // 8224
}

Assignment

File functions

Availability

CTRL