Programming in C

(Barry) #1
474 Appendix B The Standard C Library

Included in this file are declarations for the I/O functions and definitions for the names
EOF,NULL,stdin,stdout,stderr(all constant values), and FILE.
In the descriptions that follow,fileName,fileName1,fileName2,accessMode, and
formatare pointers to null-terminated strings,bufferis a pointer to a character array,
filePtris of type “pointer to FILE,”nand sizeare positive integer values of type
size_t,and iand care of type int.
void clearerr (filePtr)
Clears the end of file and error indicators associated with the file identified by
filePtr.
int fclose (filePtr)
Closes the file identified by filePtrand returns zero if the close is successful, or
returns EOFif an error occurs.
int feof (filePtr)
Returns nonzero if the identified file has reached the end of the file and returns zero
otherwise.
int ferror (filePtr)
Checks for an error condition on the indicated file and returns zero if an error exists,
and returns nonzero otherwise.
int fflush (filePtr)
Flushes (writes) any data from internal buffers to the indicated file, returning zero on
success and the value EOFif an error occurs.
int fgetc (filePtr)
Returns the next character from the file identified by filePtr, or the value EOFif an
end-of-file condition occurs. (Remember that this function returns an int.)
int fgetpos (filePtr, fpos)
Gets the current file position for the file associated with filePtr, storing it into the
fpos_t(defined in <stdio.h>) variable pointed to by fpos.fgetposreturns zero on
success, and returns nonzero on failure. See also the fsetposfunction.
char *fgets (buffer, i, filePtr)
Reads characters from the indicated file, until either i– 1 characters are read or a
newline character is read, whichever occurs first. Characters that are read are stored
into the character array pointed to by buffer. If a newline character is read, it willbe
stored in the array. If an end of file is reached or an error occurs, the value NULLis
returned; otherwise,bufferis returned.

21 0672326663 AppB 6/10/04 2:03 PM Page 474

Free download pdf