This section demonstrates you how to open a file in C.
The header file <stdio.h> provides several functions related to file operations. Here we are going to open a file using library function fopen(). You can see in the given example, we have used the type FILE in order to store the information related to file stream. Then we create a file pointer and call the function fopen("MYFILE.txt", "a") using append mode a. This will open the file MYFILE.txt and allow to perform write operations. After that the fprintf() function write the string to the file MYFILE.txt.
Here i am using TurboC++ IDE and my source file is in the C:\TC\BIN directory and the output file MYFILE.txt will generate in the same bin directory.
Here is the code:
When you run the above example, you will find that the file MYFILE.txt
is created and contains string as
Where there is will, there is a way.
We have 1000s of tutorials on our website. Search Tutorials tutorials on our website.
Posted on: February 5, 2009 If you enjoyed this post then why not add us on Google+? Add us to your Circles