Previous Page
Next Page

16.1. Input and Output

We have dealt with this topic in detail in Chapter 13, which contains sections on I/O streams, sequential and random file access , formatted I/O, and error handling. A tabular list of the I/O functions will therefore suffice here. Table 16-1 lists general file access functions declared in the header stdio.h.

Table 16-1. General file access functions

Purpose

Functions

Rename a file, delete a file

rename( ), remove( )

Create and/or open a file

fopen( ), freopen( ), tmpfile( )

Close a file

fclose( )

Generate a unique filename

tmpnam( )

Query or clear file access flags

feof( ), ferror( ), clearerr( )

Query the current file access position

ftell( ), fgetpos( )

Change the current file access position

rewind( ), fseek( ), fsetpos( )

Write buffer contents to file

fflush( )

Control file buffering

setbuf( ), setvbuf( )


There are two complete sets of functions for input and output of characters and strings: the byte-character and the wide-character I/O functions (see "Byte-Oriented and Wide-Oriented Streams" in Chapter 13 for more information). The wide-character functions operate on characters with the type wchar_t, and are declared in the header wchar.h. Table 16-2 lists both sets.

Table 16-2. File I/O functions

Purpose

Functions in stdio.h

Functions in wchar.h

Get/set stream orientation

 

fwide( )

Write characters

fputc( ), putc( ), putchar( )

fputwc( ), putwc( ), putwchar( )

Read characters

fgetc( ), getc( ), getchar( )

fgetwc( ), getwc( ), getwchar( )

Put back characters read

ungetc( )

ungetwc( )

Write lines

fputs( ), puts( )

fputws( )

Read lines

fgets( ), gets( )

fgetws( )

Write blocks

fwrite( )

 

Read blocks

fread( )

 

Write formatted strings

printf( ), vprintf( )

fprintf( ), vfprintf( )

sprintf( ), vsprintf( )

snprintf( ), vsnprintf( )

wprintf( ), vwprintf( )

fwprintf( ), vfwprintf( )

swprintf( ), vswprintf( )

Read formatted strings

scanf( ), vscanf( )

fscanf( ), vfscanf( )

sscanf( ), vsscanf( )

wscanf( ), vwscanf( )

fwscanf( ), vfwscanf( )

swscanf( ), vswscanf( )



Previous Page
Next Page