Home » fputs() and fgets() in C

fputs() and fgets() in C

by Online Tutorials Library

C fputs() and fgets()

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


Writing File : fputs() function

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

Syntax:

Example:

myfile2.txt

hello c programming 

Reading File : fgets() function

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

Syntax:

Example:

Output:

hello c programming 
Next TopicC fseek()

You may also like