File Input/Output Functions
The
classic functions for
reading from and writing to files are declared in the header file
stdio.h
.
In the descriptions that follow in Table 1-23,
fp
designates the file pointer. Those
functions that have no parameter with the file pointer type read from
stdin
or write to stdout
.
Reading and writing characters and strings
Purpose |
Functions |
Write a character |
int fputc( int |
Read a character |
int fgetc( FILE * |
Put back a character |
int ungetc( int |
Write a line |
int fputs( const char * |
Read a line |
char *fgets( char * |
For each of these input/output functions, there is also a
corresponding function for wide-oriented access. The wide functions
are declared in the header file
wchar.h
(*).
Their names are formed with wc
(for wide
character) in place of c
(for
character), or with ws
(for
wide string) in place of s
(for string).
Block read and write functions
The following file access functions can be used to read or write a block of characters:
-
size_t
fwrite
( const void *buf
, size_tsz
, size_tn
, FILE *fp
); Writes
n
objects of lengthsz
from the buffer addressed bybuf
to the file.-
size_t
fread
( void *buffer
, size_tsz
, size_tn
, FILE *fp
); Reads up to
n
objects of ...
Get C Pocket Reference now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.