What is fputs() and fgets() in C programming?

Mayanknegi
Jan 11, 2023

--

The fputs() and fgets() in C programming are used to write and read strings from streams. Let’s see examples of writing and reading files using fgets() and fgets() functions.

The fputs() function writes a line of characters into a file. It outputs a string to a stream.

Syntax:

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

The fgets() function reads a line of characters from a file. It gets a string from a stream.

Syntax:

char* fgets(char *s, int n, FILE *stream)

Learn more about fputs() and fgets() in C programming.

--

--