File handling operations using C programming

Hello There! Many times, we need to interact with the files and perform operations such as opening, writing, deleting and closing. We’ll perform all these file handling operations using C programming in this tutorial.

So, as usual, open the C emulator and type the following source code in it.

File Handling Operations

Create file and write contents in it

The following program will create the file ‘Student.txt’ and will write the contents entered by the user.

Simply run the program, you will see the output in the window as follows.

File handling operations using C programming

Now you will find the file ‘student.txt’ created and contents written in it.

Read the contents from file

The following program will show how to read the data from file and display on the output screen.

Here, we can retrieve the above created file and see the contents in it as shown in the screen below. The file name you have to enter, is not case-sensitive you can try  combination of capital and small letters.

File handling operations using C programming


That’s it! it is working fine. For any queries, you can comment in the box below.

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.