1. Format input
Return value: Three function return value is consistent, if successful, specify the number of entries entered, if the input error or the end of the file before any transformation to return EOF
(1). scanf
Prototype: int scanf (const char *restrict format, ...);
Most basic, from standard input input
(2). fscanf
Prototype: int fscanf (FILE *restrict FP, const char *restrict format, ...);
and (1) , you can specify the stream FP, no longer limit the standard input
(3). sscanf
Prototype: int sscanf (const char *restrict buf, const char *restrict fromat, ...);
and (2) In contrast, not from stream input, from array buf input
2. Formatted output
(1). printf
Most basic, write formatted data to standard output, without the problem of buffer overflow
Return value: Returns a negative if an error occurs if the output character number is successfully returned
(2). fprintf
Prototype: int fprintf (FILE *restrict FP, const char *restrict format, ...);
Return value: Returns a negative if an error occurs if the output character number is successfully returned
and (1) , you can specify the stream to write, no longer limit the standard output
(3). sprintf
Prototype: int sprintf (char *restrict buf, const *restrict format, ...);
Return value: If the number of characters in the array is successfully returned, negative values are returned if an error is encoded
In contrast to (2) , the write is no longer a stream, but an array buf, and sprintf automatically adds a null byte at the end of the array, but the byte is not included in the return value, because of the addition of a null byte, May cause a buffer overflow , the caller should be aware.
(4). snprintf
Prototypes:int sprintf (char *restrict buf, size_t N, const *restrict format, ...);
Return value: If the number of characters in the array is successfully returned, negative values are returned if an error is encoded
In addition to (3) , buffer length n is added, which resolves a buffer overflow problem , and the return value does not include a null byte
Format input and output of standard IO