FEOF

The FEOF function returns a boolean value indicating whether then last read from a file reached the end of that file or not. This can potentially be the case after any call to FGETI or FGETS.

Previous versions of XJTAG allowed FEOF to be called without any brackets. Support for this usage was removed in XJTAG v4.0.

Syntax

FEOF()
FEOF( FILE fileHandle )

Parameters

fileHandle
Optionally, the file handle to examine to see if its last read reached the end of the file. If no file handle is specified, then the result is taken from the last file that was accessed in the current session.

Return value

An INT value that indicates whether the end of the file has been reached or not.

Example

LOCAL ReadFile()()
  FILE fileHandle;
  INT value;
  STRING filename := "test.bin";

  // Open the file for reading (binary file).
  fileHandle := FOPEN(filename, "r");
  IF FERROR() THEN
    PRINT("Unable to open file ", filename, "\n");
    EXIT;
  END;

  // Read from the file and print the value, if and
  // only if the value read was not the end of file
  // and there was no error in reading.
  DO
    value := FGETI(fileHandle, WIDTHOF(value));
  WHILE !(FEOF(fileHandle) ||? FERROR(fileHandle))
    PRINT("0x", HEX(value));
  END;

  IF FERROR(fileHandle) THEN
    PRINT("Error reading from file ", filename, "\n");
    FCLOSE(fileHandle);
    EXIT;
  END;

  FCLOSE(fileHandle);
END;

See Also