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

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

File access

FunctionsDescription
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

FunctionsDescription
fprintf() Writes formatted data to stream.
fscanf() Reads formatted data from stream.
printf() Prints formatted data to stdout.
scanf() Prints formatted data to stdout.
sprintf() Writes formatted data to a string.
snprintf() Writes formatted data to a sized buffer.
sscanf() Reads formatted data from string.
vfprintf() Writes formatted data from variable argument list to stream
vfscanf() Reads formatted data from stream into variable argument list
vprintf() Prints formatted data from variable argument list to stdout
vscanf() Reads formatted data into variable argument list
vsnprintf() Writes formatted data from variable argument list to sized buffer
vsprintf() Writes formatted data from variable argument list to string
vsscanf() Reads formatted data from string into variable argument list

Unformatted input/output

FunctionsDescription
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 the stream.

Direct input/output

FunctionsDescription
fread() Read block of data from stream.
fwrite() Write block of data to stream.

File positioning

FunctionsDescription
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

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

Library Types

TypesDescription
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

MacrosDescription
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

MacrosDescription
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.
SEEK_SET
SEEK_CUR
SEEK_END
Argument to fseek() function indicating seeking from beginning of the file, from the current file position, and from end of the file respectively.
_IOFBF
_IOLBF
_IONBF
Argument to setvbuf() function indicating fully buffered I/O, line buffered I/O and unbuffered I/O respectively.