C Standard Library - <stdio.h>


Introduction

stdio .h The header file defines three variable types, some macros and various functions to perform input and output.

Library variables

The following are the variable types defined in the header file stdio.h:

Serial numberVariables & Description
1size_t
This is the unsigned integer type, which is the sizeof keyword result.
2FILE
This is an object type suitable for storing file stream information.
3fpos_t
This is an object type suitable for storing anywhere in a file.

Library macros

The following are the macros defined in the header file stdio.h:

Serial numberMacro & Description
1NULL
This macro is the value of a null pointer constant.
2_IOFBF, _IOLBF and _IONBF
These macros expand integers with specific values Constant expression, and applies to the third argument of the setvbuf function.
3BUFSIZ
This macro is an integer, which represents the buffer used by the setbuf function area size.
4EOFM
This macro is a negative integer indicating that the end of the file has been reached.
5FOPEN_MAX
This macro is an integer that represents the number of files that the system can open at the same time.
6FILENAME_MAX
This macro is an integer that represents the maximum length of a file name that can be stored in a character array. If the implementation does not have any restrictions, this value should be the recommended maximum.
7L_tmpnam
This macro is an integer that represents the temporary created by the tmpnam function that can be stored in the character array. The maximum length of the file name.
8SEEK_CUR, SEEK_END and SEEK_SET
These macros are used in the fseek Used in the function to locate different locations in a file.
9TMP_MAX
This macro is the maximum number of unique file names that can be generated by the tmpnam function.
10stderr, stdin and stdout
These macros are pointers to the FILE type, corresponding to for the standard error, standard input, and standard output streams.

Library functions

The following are the functions defined in the header file stdio.h:

In order to better understand the functions, please follow the sequence below to learn these functions, because the files created in the first function will be used in subsequent functions.
##1int fclose(FILE *stream )2void clearerr(FILE *stream)3int feof(FILE *stream)4int ferror(FILE *stream)5int fflush(FILE *stream)6int fgetpos(FILE *stream, fpos_t *pos)7FILE *fopen(const char *filename, const char *mode)8size_t fread(void *ptr, size_t size, size_t nmemb, FILE *stream)9FILE *freopen(const char *filename, const char *mode, FILE *stream)10int fseek(FILE *stream, long int offset, int whence)11int fsetpos(FILE *stream, const fpos_t *pos)12long int ftell(FILE *stream)13size_t fwrite(const void *ptr, size_t size, size_t nmemb, FILE *stream)14int remove(const char *filename)15int rename(const char *old_filename, const char *new_filename)16void rewind(FILE *stream)17void setbuf(FILE *stream, char *buffer)18int setvbuf(FILE *stream, char *buffer, int mode, size_t size)19FILE *tmpfile(void)
Serial numberFunction & Description
Close the stream stream. Flush all buffers.
Clears the end-of-file and error identifiers of the given stream stream.
Tests the end-of-file identifier of the given stream stream.
Test the error identifier of the given stream stream.
Flush the output buffer of stream stream.
Get the current file position of stream stream and write it to pos.
Open the file pointed to by filename using the given mode mode.
Read data from the given stream stream to ptr. in the array pointed to.
Put a new file name filename with the given Open the stream association while closing the old file in the stream.
Set the file position of the stream stream to the given offset offset, Parameter
offset means the number of bytes to look for from the given whence position.
Set the file position of the given stream stream to the given position. The argument
pos is the position given by the function fgetpos.
Returns the current file position of the given stream stream.
Write the data in the array pointed to by ptr Into the given stream stream.
Removes the given filename filename so that it is no longer accessed.
Change the file name pointed to by old_filename to new_filename.
Sets the file position to the beginning of the file for the given stream stream.
Define how the stream stream should be buffered.
Another function that defines how the stream stream should be buffered.
Create temporary files in binary update mode (wb+).
20char *tmpnam(char *str)
Generate and return a valid temporary file name that did not exist before.
21int fprintf(FILE *stream, const char *format, ...)
Send formatted output to the stream stream.
22int printf(const char *format, ...)
Send formatted output to the standard output stdout.
23int sprintf(char *str, const char *format, ...)
Send formatted output to a string.
24int vfprintf(FILE *stream, const char *format, va_list arg)
Send formatted output to the stream stream using a parameter list.
25int vprintf(const char *format, va_list arg)
Sends formatted output to stdout using the argument list.
26int vsprintf(char *str, const char *format, va_list arg)
Send formatted output to a string using an argument list.
27int fscanf(FILE *stream, const char *format, ...)
Read formatted input from stream stream.
28int scanf(const char *format, ...)
Read formatted input from the standard input stdin.
29int sscanf(const char *str, const char *format, ...)
Read formatted input from a string.
30int fgetc(FILE *stream)
Get the next character (an unsigned character) from the specified stream stream and put the position identifier Move forward.
31char *fgets(char *str, int n, FILE *stream)
Read a line from the specified stream stream and store it Within the string pointed to by str. It stops when (n-1) characters are read, a newline character is read, or the end of the file is reached, as appropriate.
32int fputc(int char, FILE *stream)
Write the character specified by parameter char (an unsigned character) to the specified stream stream and move the position identifier forward.
33int fputs(const char *str, FILE *stream)
Write the string into the specified stream stream, but does not include null character.
34int getc(FILE *stream)
Get the next character (an unsigned character) from the specified stream stream and put the position identifier Move forward.
35int getchar(void)
Get a character (an unsigned character) from the standard input stdin.
36char *gets(char *str)
Read a line from the standard input stdin and store it in the string pointed to by str . It stops when a newline character is read, or when the end of the file is reached, as the case may be.
37int putc(int char, FILE *stream)
Write the character specified by parameter char (an unsigned character) to the specified stream stream and move the position identifier forward.
38int putchar(int char)
Writes the character specified by the char parameter (an unsigned character) to the standard output stdout.
39int puts(const char *str)
Write a string to the standard output stdout until, but not including, the null character . Newlines are appended to the output.
40int ungetc(int char, FILE *stream)
Push the character char (an unsigned character) into the specified stream stream, so that it is the next character to be read.
41void perror(const char *str)
Output a descriptive error message to standard error stderr. The string str is output first, followed by a colon and then a space.