C Standard Library

C - <stdio.h>

The C <stdio.h> header provides generic file operation support and defines a number of functions with narrow and multibyte character input/output capabilities, and the <wchar.h> header provides functions with wide character input/output capabilities. These functions are available to use in a current program after including the header file using - #include <stdio.h>. Functions and macros of this header file are listed below:

Library Functions

Operations on files

remove() Deletes a file.
rename() Renames a file.
tmpfile() Open a temporary file.
tmpnam() Generate temporary filename.

File access

fclose() Closes a file.
fflush() Flush stream.
fopen() Opens a file.
freopen() Reopen stream with different file or mode.
setbuf() Set stream buffer.
setvbuf() Change stream buffering.

Formatted input/output

printf() Prints formatted data to stdout.
fprintf() Writes formatted data to stream.
fscanf() Reads formatted data from stream.
sprintf() Writes formatted data to a string.
snprintf() Writes formatted data to a sized buffer.

Unformatted input/output

fgetc() Gets character from stream.
fgets() Gets string from stream.
getc() Get character from stream.
getchar() Get character from stdin.
gets() Gets string from stdin.
fputc() Writes character to stream.
fputs() Writes string to stream.
putc() Writes character to stream.
putchar() Writes character to stdout.
puts() Writes string to stdout.
ungetc() Puts a character back into a file stream.

File positioning

fgetpos() Gets the current file position indicator.
fseek() Moves the file position indicator to a specific location.
fsetpos() Sets the file position indicator to a specific location.
ftell() Returns the current file position indicator.
rewind() Sets the file position indicator to the beginning.

Error handling

clearerr() Clear error indicators.
feof() Check end-of-file indicator.
ferror() Checks for a file error.

Library Types

FILE Object type, capable of holding all information needed to control a stream.
fpos_t Object containing information to specify a position within a file.
size_t Unsigned integer type.

Library Macros

Predefined standard streams

stdin Expression of type FILE* associated with the input stream.
stdout Expression of type FILE* associated with the output stream.
stderr Expression of type FILE* associated with the error output stream.

Macro constants

BUFSIZ Buffer size.
EOF End-of-File.
FILENAME_MAX Maximum length of file names.
FOPEN_MAX Number of files that can be open simultaneously.
L_tmpnam Size needed for an array of char to hold the result of tmpnam() function.
NULL Null pointer.
TMP_MAX Maximum number of unique filenames that is guaranteed to be possible to generate using tmpnam() function.
Argument to fseek() function indicating seeking from beginning of the file, from the current file position, and from end of the file respectively.
Argument to setvbuf() function indicating fully buffered I/O, line buffered I/O and unbuffered I/O respectively.