The file named called EMPLOYEE.txt contains employee details such as employee number, name, designation and salary of employee. Write a program to create a file to store the details of employee (Use of structure and fwrite () & fread () functions).
#include <stdio.h>
struct Employee {
int number;
char name[20];
char design[20];
int salary;
};
int main() {
struct Employee data[5] = {{1, "John Smith", "AAA", 10000},
{2, "Adam Brown", "BBB", 20000},
{3, "Bob Armor", "CCC", 15000},
{4, "Charly Crown", "DDD", 25000},
{5, "Duglas Dow", "EEE", 1000}};
int i;
FILE *pFile;
pFile = fopen("EMPLOYEE.txt", "wb");
fwrite(data, sizeof(struct Employee), 5, pFile);
fclose(pFile);
return 0;
}
Comments
Leave a comment