Skip to content
Tuesday, December 1, 2026Ideas worth exploring. Knowledge worth sharing.
S. SenseCentralDISCOVER EVERY DAY
Programming & Data Structures

C Program to Write a Sentence to a File

In this example, you will learn to write a sentence in a file using fprintf() statement.

To understand this example, you should have the knowledge of the following C programming topics:

·         C File Handling

·         C Standard Library Functions

This program stores a sentence entered by the user in a file.

1.       

Output

Enter a sentence: C Programming is fun

Here, a file named program.txt is created. The file will contain C programming is fun text.

In the program, the sentence entered by the user is stored in the sentence variable.

Then, a file named program.txt is opened in writing mode. If the file does not exist, it will be created.

Finally, the string entered by the user will be written to this file using the fprintf() function and the file is closed.

Author

  • A senior editor for The Mars that left the company to join the team of SenseCentral as a news editor and content creator. An artist by nature who enjoys video games, guitars, action figures, cooking, painting, drawing and good music.

WRITTEN BY

Taylor Emma

A senior editor for The Mars that left the company to join the team of SenseCentral as a news editor and content creator. An artist by nature who enjoys video games, guitars, action figures, cooking, painting, drawing and good music.

More from this author ↗

Leave a Reply

Your email address will not be published. Required fields are marked *