20.09.2015 Views

Programming in C

Kochan - ProgramminginC

Kochan - ProgramminginC

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

474 Appendix B The Standard C Library<br />

Included <strong>in</strong> this file are declarations for the I/O functions and def<strong>in</strong>itions for the names<br />

EOF, NULL, std<strong>in</strong>, stdout, stderr (all constant values), and FILE.<br />

In the descriptions that follow, fileName, fileName1, fileName2, accessMode, and<br />

format are po<strong>in</strong>ters to null-term<strong>in</strong>ated str<strong>in</strong>gs, buffer is a po<strong>in</strong>ter to a character array,<br />

filePtr is of type “po<strong>in</strong>ter to FILE,” n and size are positive <strong>in</strong>teger values of type<br />

size_t,and i and c are of type <strong>in</strong>t.<br />

void clearerr (filePtr)<br />

Clears the end of file and error <strong>in</strong>dicators associated with the file identified by<br />

filePtr.<br />

<strong>in</strong>t fclose (filePtr)<br />

Closes the file identified by filePtr and returns zero if the close is successful, or<br />

returns EOF if an error occurs.<br />

<strong>in</strong>t feof (filePtr)<br />

Returns nonzero if the identified file has reached the end of the file and returns zero<br />

otherwise.<br />

<strong>in</strong>t ferror (filePtr)<br />

Checks for an error condition on the <strong>in</strong>dicated file and returns zero if an error exists,<br />

and returns nonzero otherwise.<br />

<strong>in</strong>t fflush (filePtr)<br />

Flushes (writes) any data from <strong>in</strong>ternal buffers to the <strong>in</strong>dicated file, return<strong>in</strong>g zero on<br />

success and the value EOF if an error occurs.<br />

<strong>in</strong>t fgetc (filePtr)<br />

Returns the next character from the file identified by filePtr, or the value EOF if an<br />

end-of-file condition occurs. (Remember that this function returns an <strong>in</strong>t.)<br />

<strong>in</strong>t fgetpos (filePtr, fpos)<br />

Gets the current file position for the file associated with filePtr, stor<strong>in</strong>g it <strong>in</strong>to the<br />

fpos_t (def<strong>in</strong>ed <strong>in</strong> ) variable po<strong>in</strong>ted to by fpos. fgetpos returns zero on<br />

success, and returns nonzero on failure. See also the fsetpos function.<br />

char *fgets (buffer, i, filePtr)<br />

Reads characters from the <strong>in</strong>dicated file, until either i – 1 characters are read or a<br />

newl<strong>in</strong>e character is read, whichever occurs first. Characters that are read are stored<br />

<strong>in</strong>to the character array po<strong>in</strong>ted to by buffer. If a newl<strong>in</strong>e character is read, it will be<br />

stored <strong>in</strong> the array. If an end of file is reached or an error occurs, the value NULL is<br />

returned; otherwise, buffer is returned.

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!