This C Program creates a file & store information. We frequently use files for storing information which can be processed by our programs. In order to store information permanently and retrieve it we need to use files and this program demostrate file creation and writing data in that.
Here is source code of the C program to create a file & store information.The C program is successfully compiled and run on a Linux system. The program output is also shown below.
* C program to create a file called emp.rec and store information
* about a person, in terms of his name, age and salary.
/* open for writing */
fptr = fopen("emp.rec", "w");
if (fptr == NULL)
printf("File does not exists \n");
printf("Enter the name \n");
fprintf(fptr, "Name = %s\n", name);
printf("Enter the age\n");
fprintf(fptr, "Age = %d\n", age);
printf("Enter the salary\n");
fprintf(fptr, "Salary = %.2f\n", salary);
$ cc pgm95.c $ a.out Enter the name raj Enter the age 40 Enter the salary 4000000
Sanfoundry Global Education & Learning Series – 1000 C Programs.
Subscribe Now: C Programs Newsletter | Important Subjects Newsletters
Here’s the list of Best Books in C Programming, Data-Structures and Algorithms
If you wish to look at other example programs on File Handling, go to C Programming Examples on File Handling . If you wish to look at programming examples on all topics, go to C Programming Examples.
- Get Free Certificate of Merit in C Programming
- Participate in C Programming Certification Contest
- Become a Top Ranker in C Programming
- Take C Programming Tests
- Chapterwise Practice Tests: Chapter 1, 2, 3, 4, 5, 6, 7, 8, 9, 10
- Chapterwise Mock Tests: Chapter 1, 2, 3, 4, 5, 6, 7, 8, 9, 10
- Practice Computer Science MCQs
- Buy Computer Science Books
- Practice BCA MCQs
- Watch Advanced C Programming Videos
- Buy C Books