1 function input
The following two functions provide the function of inputting a row at a time.
# Include <stdio. h> char * fgets (char * restrict Buf, int N, file * restrict FP); char * gets (char * BUF); two function return values: If successful, the return value is Buf, if the end of the file is reached or an error occurs, null is returned.
Both functions specify the buffer address, and the row to be read is sent to it. Gets reads from the standard input, while fgets reads from the specified stream.
2 function output
Provides the ability to output a row at a time.
# Include <stdio. h> int fputs (const char * restrict STR, file * restrict FP); int puts (const char * Str); two function return values: If successful, non-negative values are returned, if an error occurs, EOF is returned.
Example:
# Include <stdio. h>
# Define N 9
Char Buf [N];
Int main ()
{
Int I;
If (fgets (BUF, N, stdin )! = NULL)
Printf ("fgets success \ n ");
Else printf ("fgets error \ n ");
I = fputs (BUF, stdout );
If (I> 0) printf ("\ n fputs success \ n ");
Else printf ("\ n fputs error \ n ");
Return 0;
}
Fgets and fputs Functions