Borland C++ reference

eof

raw OCR

Checks for end-of-file.

Defined in header <io.h>

Syntax

#include <io.h>
int eof (int handle);

Portability

DOSUNIXWindowsANSI CC++ only
■■

Remarks

eof determines whether the file associated with handle has reached end-of-file.

Return value

If the current position is end-of-file, eof returns the value 1; otherwise, it returns 0. A return value of -1 indicates an error; the global variable errno is set to

EBADF Bad file number

See also

Example

#include <process.h>
#include <string.h>
#include <stdio.h>
#include <io.h>

int main(void)
{
   FILE *temp_file;
   int handle;
   char insg[] = "This is a test", ch;

   /* create a unique temporary file */
   if ((temp_file = tmpfileO)  == NULL)  {
      perror("OPENING FILE:");
      exit(l);
   }
   /* get handle associated with file */
   handle = fileno(temp_file);

   /* write some data to the file */
   write(handle, msg, strlen(msg));

   /* seek to the beginning of the file */
   Iseek(handle, 0L, SEEK_SET) ;
   /* reads chars from the file until EOF is hit  */
   do {
      read (handle, Sich, 1);
      printf("%c", ch);
} while (!eof(handle));

/* close and remove the temporary file  */
fclose(temp_file);
return 0;

Differences from modern implementations

Nothing recorded yet.

Modern references

These are search links, not yet checked by hand.