In this program, we are going to share a C program to create a file & store information. If you are a beginner and want to start learning the C programming, then keep your close attention in this tutorial as I am going to share a C program to create a file & store information with the output.
We have designed this program for beginners for learning purpose. Copy below c program and execute it with c compiler to see the output of the program.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 | #include <stdio.h> void main() { FILE *fptr; char name[20]; int age; float salary; /* open for writing */ fptr = fopen("emp.rec", "w"); if (fptr == NULL) { printf("File does not exists \n"); return; } printf("Enter the name \n"); scanf("%s", name); fprintf(fptr, "Name = %s\n", name); printf("Enter the age\n"); scanf("%d", &age); fprintf(fptr, "Age = %d\n", age); printf("Enter the salary\n"); scanf("%f", &salary); fprintf(fptr, "Salary = %.2f\n", salary); fclose(fptr); } |
Liked this program? Do Like & share with your friends.
If you like FreeWebMentor and you would like to contribute, you can write an article and mail your article to [email protected] Your article will appear on the FreeWebMentor main page and help other developers.