Mode | description |
---|---|
r | opens a text file in reading mode |
w | opens or create a text file in writing mode. |
r+ | opens a text file in append mode |
opens a text file in both reading and writing mode | |
w+ | opens a text file in both reading and writing mode |
a+ | opens a text file in both reading and writing mode |
rb | opens a binary file in reading mode |
wb | opens or create a binary file in writing mode |
ab | opens a binary file in append mode |
rb+ | opens a binary file in both reading and writing mode |
wb+ | opens a binary file in both reading and writing mode |
ab+ | opens a binary file in both reading and writing mode |
C open function returns NULL in case of failure, and returns a FILE Stream Pointer on success
#include<stdio.h>
int main()
{
FILE *fp;
fp = fopen(“fileName.txt”, “w”);
return 0;
}
• The above example will create file called fileName.txt
• The “w” means that the file is being opened for writing, and if the file does not exist then new file will be created.