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).
Runtime Input :
101 xyz workshop 8500
102 nmo computer 6750
103 abc store 5890
#include <stdio.h>
struct employee {
int number;
char *name;
int designation;
}
void write(FILE *f, struct employee) {
fwrite(&employee.number, sizeof(int), 1, f);
fwrite(employee.name, sizeof(char) * strlen(employee.name), 1, f);
fwrite(employee.designation, sizeof(int), 1, f);
}
int main() {
FILE *f = fopen('EMPLOYEE.txt', 'rb');
struct employee emp;
emp.number = 1;
emp.name = 'John';
emp.designation = 3455;
write(f, emp);
return 0;
}
Comments
Leave a comment