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 number | Variables & Description |
---|---|
1 | size_t This is the unsigned integer type, which is the sizeof keyword result. |
2 | FILE This is an object type suitable for storing file stream information. |
3 | fpos_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 number | Macro & Description |
---|---|
1 | NULL 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. |
3 | BUFSIZ This macro is an integer, which represents the buffer used by the setbuf function area size. |
4 | EOFM This macro is a negative integer indicating that the end of the file has been reached. |
5 | FOPEN_MAX This macro is an integer that represents the number of files that the system can open at the same time. |
6 | FILENAME_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. |
7 | L_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. |
8 | SEEK_CUR, SEEK_END and SEEK_SET These macros are used in the fseek Used in the function to locate different locations in a file. |
9 | TMP_MAX This macro is the maximum number of unique file names that can be generated by the tmpnam function. |
10 | stderr, 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.
Serial number | Function & Description |
---|---|
int fclose(FILE *stream ) | Close the stream stream. Flush all buffers. |
void clearerr(FILE *stream) | Clears the end-of-file and error identifiers of the given stream stream. |
int feof(FILE *stream) | Tests the end-of-file identifier of the given stream stream. |
int ferror(FILE *stream) | Test the error identifier of the given stream stream. |
int fflush(FILE *stream) | Flush the output buffer of stream stream. |
int fgetpos(FILE *stream, fpos_t *pos) | Get the current file position of stream stream and write it to pos. |
FILE *fopen(const char *filename, const char *mode) | Open the file pointed to by filename using the given mode mode. |
size_t fread(void *ptr, size_t size, size_t nmemb, FILE *stream) | Read data from the given stream stream to ptr. in the array pointed to. |
FILE *freopen(const char *filename, const char *mode, FILE *stream) | Put a new file name filename with the given Open the stream association while closing the old file in the stream. |
int fseek(FILE *stream, long int offset, int whence) | 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. |
int fsetpos(FILE *stream, const fpos_t *pos) | Set the file position of the given stream stream to the given position. The argument pos is the position given by the function fgetpos. |
long int ftell(FILE *stream) | Returns the current file position of the given stream stream. |
size_t fwrite(const void *ptr, size_t size, size_t nmemb, FILE *stream) | Write the data in the array pointed to by ptr Into the given stream stream. |
int remove(const char *filename) | Removes the given filename filename so that it is no longer accessed. |
int rename(const char *old_filename, const char *new_filename) | Change the file name pointed to by old_filename to new_filename. |
void rewind(FILE *stream) | Sets the file position to the beginning of the file for the given stream stream. |
void setbuf(FILE *stream, char *buffer) | Define how the stream stream should be buffered. |
int setvbuf(FILE *stream, char *buffer, int mode, size_t size) | Another function that defines how the stream stream should be buffered. |
FILE *tmpfile(void) | Create temporary files in binary update mode (wb+). |
20 | char *tmpnam(char *str) Generate and return a valid temporary file name that did not exist before. |
21 | int fprintf(FILE *stream, const char *format, ...) Send formatted output to the stream stream. |
22 | int printf(const char *format, ...) Send formatted output to the standard output stdout. |
23 | int sprintf(char *str, const char *format, ...) Send formatted output to a string. |
24 | int vfprintf(FILE *stream, const char *format, va_list arg) Send formatted output to the stream stream using a parameter list. |
25 | int vprintf(const char *format, va_list arg) Sends formatted output to stdout using the argument list. |
26 | int vsprintf(char *str, const char *format, va_list arg) Send formatted output to a string using an argument list. |
27 | int fscanf(FILE *stream, const char *format, ...) Read formatted input from stream stream. |
28 | int scanf(const char *format, ...) Read formatted input from the standard input stdin. |
29 | int sscanf(const char *str, const char *format, ...) Read formatted input from a string. |
30 | int fgetc(FILE *stream) Get the next character (an unsigned character) from the specified stream stream and put the position identifier Move forward. |
31 | char *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. |
32 | int 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. |
33 | int fputs(const char *str, FILE *stream) Write the string into the specified stream stream, but does not include null character. |
34 | int getc(FILE *stream) Get the next character (an unsigned character) from the specified stream stream and put the position identifier Move forward. |
35 | int getchar(void) Get a character (an unsigned character) from the standard input stdin. |
36 | char *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. |
37 | int 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. |
38 | int putchar(int char) Writes the character specified by the char parameter (an unsigned character) to the standard output stdout. |
39 | int 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. |
40 | int 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. |
41 | void 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. |