Stdio.h
Encyclopedia : S : ST : STD : Stdio.h
| C++ standard library>C++ Standard Library headers |
| C Standard Library headers |
|---|
| assert.h |
| ctype.h |
| errno.h |
| float.h |
| math.h |
| stdio.h |
| stdlib.h |
| time.h |
- The correct title of this } is }}}. The initial letter is capitalized due to [Naming conventions #Lower case first lettertechnical restrictions].
Functions declared in stdio.h are extremely popular, since as a part of the C standard library, they are guaranteed to work on any platform which supports C. Applications on a particular platform might, however, have reasons to use the platform's I/O routines, rather than the stdio.h routines.
Example usage
All functions in C and its derivatives are declared in from header files. Thus, programmers have to include thestdio.h header into the source code to utilize the functions declared there.
#include int main(void)
The above program reads all input from the standard input and echo it onto the standard output, line by line.
Member functions
Functions declared instdio.h can generally be divided into two categories: the functions for file manipulation and the functions for input-output manipulation.
| Name | Description |
|---|---|
| File manipulation functions | |
| fclose | closes a file associated with the FILE * value passed to it |
| fopen, freopen, fdopen | opens a file for certain types of reading or writing |
| remove | removes a file (deletes it) |
| rename | renames a file |
| rewind | acts as if fseek(stream, 0L, SEEK_SET) was called for the stream passed, and then its error indicator cleared |
| tmpfile | creates and open a temporary file, which is deleted when closed with fclose() |
| Input-output manipulation functions | |
| clearerr | clears end-of-file and error indicators for a given stream |
| feof | checks whether an end-of-file indicator has been set for a given stream |
| ferror | checks whether an error indicator has been set for a given stream |
| fflush | forces any pending buffered output to be written to the file associated with a given stream |
| fgetpos | stores the file position indicator of the stream associated by its first argument (a FILE *) to its second argument (a fpos_t *) |
| fgetc | returns one character from a file |
| fgets | gets a string from the file (ends at newline or null character) |
| fputc | writes one character to a file |
| fputs | writes a string to a file |
| ftell | returns a file-position indicator which can then be passed to fseek |
| fseek | seeks through a file |
| fsetpos | sets the file position indicator of a stream associated by its first argument (a FILE *) as stored in its second argument (a fpos_t *) |
| fread | reads different sized data from a file |
| fwrite | writes different sized data to a file |
| getc | reads and returns a character from a given stream and advances the file position indicator; it is allowed to be a macro with the same effects as fgetc, except that it may evaluate the stream more than once |
| getchar | has the same effects as getc(stdin) |
| gets | reads characters from stdin until a newline is encountered and stores them in its only argument |
| printf, fprintf, sprintf, snprintf | used to print to stdout |
| vprintf | also used to print to stdout |
| perror | writes an error message to stderr |
| putc | writes and returns a character to a stream and advances the file position indicator for it; it is allowed to be a macro with the same effects as fputc, except that it may evaluate the stream more than once |
| putchar, fputchar | has the same effects as putc(stdin) |
| scanf, fscanf, sscanf | used to input from stdin |
| vfscanf, vscanf, vsscanf | also used to input from stdin |
| setbuf | |
| setvbuf | sets the buffering mode for a given stream |
| tmpnam | creates a temporary filename and stores it in its first argument (a char *) |
| ungetc | pushes a character back onto a stream |
| puts | outputs a character string to stdout |
Member constants
Constants defined in thestdio.h header include:
| Name | Value | Notes |
|---|---|---|
| EOF | a negative integer of type int used to indicate end-of-file conditions.
| |
BUFSIZ
| an integer which is the size of the buffer used by the setbuf() function.
| |
FILENAME_MAX
| the size of a char array which is large enough to store the name of any file that can be opened.
| |
FOPEN_MAX
| the number of files that may be open simultaneously. Will be at least 8. | |
_IOFBF
| an abbreviation for "input/output fully buffered"; it is an integer which may be passed to the setvbuf() function to request block buffered input and output for an open stream.
| |
_IOLBF
| an abbreviation for "input/output line buffered"; it is an integer which may be passed to the setvbuf() function to request line buffered input and output for an open stream.
| |
_IONBF
| an abbreviation for "input/output not buffered"; it is an integer which may be passed to the setvbuf() function to request unbuffered input and output for an open stream.
| |
L_tmpnam
| the size of a char array which is large enough to store a temporary filename generated by the tmpnam() function.
| |
NULL
| 0 | a macro expanding to the null pointer constant; that is, a constant representing a pointer value which is guaranteed not to be a valid address of an object in memory. |
SEEK_CUR
| an integer which may be passed to the fseek() function to request positioning relative to the current file position.
| |
SEEK_END
| an integer which may be passed to the fseek() function to request positioning relative to the end of the file.
| |
SEEK_SET
| an integer which may be passed to the fseek() function to request positioning relative to the beginning of the file.
| |
TMP_MAX
| the maximum number of unique filenames generable by the tmpnam() function. Will be at least 25.
|
Member variables
Variables defined in thestdio.h header include:
| stdin | a pointer to FILE which refers to the standard input stream, usually a keyboard.
|
| stdout | a pointer to FILE which refers to the standard output stream, usually a display terminal.
|
| stderr | a pointer to FILE which refers to the standard error stream, often a display terminal.
|
Member
Data types defined in the stdio.h header include:
FILE - a structure containing the information about a file or text stream needed to perform input or output operations on it, including:- * the current stream position
- * an end-of-file indicator
- * an error indicator
- * a pointer to the stream's buffer, if applicable
fpos_t - a non-array type capable of uniquely identifying the position of every byte in a file.size_t - an unsigned integer type which is the type of the result of the sizeof operator.
From Wikipedia, the Free Encyclopedia. Original article here. Support Wikipedia by contributing or donating.
All text is available under the terms of the GNU Free Documentation License See Wikipedia Copyrights for details.
FILE - a structure containing the information about a file or text stream needed to perform input or output operations on it, including:fpos_t - a non-array type capable of uniquely identifying the position of every byte in a file.size_t - an unsigned integer type which is the type of the result of the sizeof operator.All text is available under the terms of the GNU Free Documentation License See Wikipedia Copyrights for details.
