eof
Go Up to io.h Index
Header File
io.h
Category
Input/output Routines
Prototype
int eof(int handle);
Description
Checks for end-of-file.
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 |
Example
#include <sys\stat.h> #include <string.h> #include <stdio.h> #include <fcntl.h> #include <io.h> int main(void) { int handle; char msg[] = "This is a test"; char ch; /* create a file */ handle = open("DUMMY.FIL", O_CREAT | O_RDWR, S_IREAD | S_IWRITE); /* write some data to the file */ write(handle, msg, strlen(msg)); /* seek to the beginning of the file */ lseek(handle, 0L, SEEK_SET); /* reads chars from the file until it reaches EOF */ do { read(handle, &ch, 1); printf("%c", ch); } while (!eof(handle)); close(handle); return 0; }
Portability
POSIX | Win32 | ANSI C | ANSI C++ |
---|---|---|---|
+ |