programming-examples/c/Data_Input_Output/C Program to Create a File & Store Information.c
2019-11-15 12:59:38 +01:00

30 lines
752 B
C

/*
* C program to create a file called emp.rec and store information
* about a person, in terms of his name, age and salary.
*/
#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);
}