Code:
#include <stdio.h>
#include <stdlib.h>
struct date {
int month;
int day;
int year;
};
struct empRec{
char name[25];
char room[10];
int jobLevel;
struct date startDate;
};
int main(){
FILE *data;
static struct empRec employee[1000]={
{"Peter North","4B-208",35400,{10,11,1983}},
{"John Musa","2B-118",25400,{07,10,1993}},
{"Paula Jeminova","1A-506",18700,{02,1,1990}},
{"Patricia Silver","6C-123",52100,{14,21,2000}},
{"Robert mill","4D-318",42100,{01,19,2008}},
};
struct empRec employee2;
if((data=fopen("database","w+"))==NULL){
fprintf(stderr,"Can't Create database\n");
exit(1);
}
if(fwrite(&employee,sizeof(struct empRec),1,data)!=1){
fprintf(stderr,"WRITE ERROR\n");
exit(1);
}
rewind(data);
fread(&employee,sizeof(struct empRec),1,data);
int n;
for (n = 0; n < employee.length; n++) {
printf("%s %s %d %d %d %d\n", employee[n].name, employee[n].room, employee[n].jobLevel, employee[n].startDate.month, employee[n].startDate.day, employee[n].startDate.year);
}
fclose(data);
printf("Created database\n");
exit(0);
}