Input and Output

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

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. The wide-character functions operate on characters with the type wchar_t, and are declared in the header wchar.h. Following Table lists both sets.

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( )