Create a file using file handling in c
In the program, you will get an example code to create a file using file handling in c. This is a simple program of files in c programming language, to create a file.
File Handling in C
File Handling in C is the way to storing of data in a file using c programming. In C programming language, we can store data/results in a file through the program of file handling in C. Thereafter whenever we required, we can extract data from the file.
File modes used in File Handling in C
Mode | Meaning | Description |
r | Read | Open file in read mode. |
w | Write | Open or creates file(if not exist) in write mode and erase old content of file. |
r+ | read + write | for reading and writing, create file(if not exist), overwrite old data |
w+ | read + write | Opens or creates file in write mode. |
a+ | read + append | Opens file in append mode. |
rb | read in binary mode | Open for reading in binary mode. |
wb | write in binary mode | Open file for writing in binary mode. |
ab | append in binary mode | Open for append in binary mode |
File Handling in C program
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 | //C program to Create a File #include<stdio.h> main() { FILE *fp; char c; //Create a fie fp=fopen("coderevise.txt","w"); if(!fp) { printf("Error in creating file!!!"); return 0; } printf("File created successfully."); <span data-offset-key="7toj3-97-0">f</span><span data-offset-key="7toj3-98-0">close</span><span data-offset-key="7toj3-99-0">(</span><span data-offset-key="7toj3-100-0">fp</span><span data-offset-key="7toj3-101-0">);</span> return 0; } |
Output
Check out our other C programming Examples