The fgets() function and fputs() function of the C language

fgets() function

Prototype: char *fgets(char *str, int n, FILE *stream)

parameter:

str – This is a pointer to a character array to store the string to be read.

n – This is the maximum number of characters to read (including the final null character). Usually the length of the array passed as str is used.

stream – This is a pointer to a FILE object that identifies the stream from which characters are to be read.

Header file: <stdio.h>

Function: Read a line from the specified stream and store it in the string pointed to by str. It stops when (n-1) characters have been read, or when a newline character has been read, or when the end of the file has been reached, as the case may be.

If successful, the function returns the same str parameter. If the end of the file is reached or no characters are read, the contents of str are unchanged and a null pointer is returned.

If an error occurs, returns a null pointer.

If fgets() reads a newline, it stores the newline in the string.

fputs() function

prototype:

int fputs(const char *str, FILE *stream)

parameter

str – This is an array containing the null-terminated sequence of characters to be written.
stream – this is a pointer to a FILE object identifying the stream to which the string is to be written

return value

The function returns a non-negative value, or EOF if an error occurs.

Guess you like

Origin blog.csdn.net/chengkai730/article/details/132395958