Source:
#include "/home/cordless/chomework/headerlib/dbstruct.h"
int main() {
struct person read_database[10];
FILE *dbfile;
int i;
dbfile=fopen("mycensus.dat","rb");
fread(read_database,sizeof(struct people),10,dbfile);
for (i=0;i<10;i++) {
printf("Name: %s\nAge: %d\nSex: %c\nBirthDate: %d/%d/%d\n",read_database[i].name,read_database[i].age,read_database[i].sex,read_database[i].day,read_database[i].month,read_database[i].year);
}
getchar();
}
Header:
#include <stdio.h>
struct person {
char name[80];
int age;
char sex;
int month;
int day;
int year;
}
Database generate Source:
#include "/home/cordless/chomework/headerlib/dbstruct.h"
int main() {
FILE *database;
struct person person[10];
int i;
for(i=0;i<=9;i++) {
printf("Enter the persons Name: ");
scanf("%s",person[i].name);
printf("Enter the person's Age: ");
scanf("%d",&(person[i].age));
printf("Enter the person's Sex (M or F): ");
getchar();
scanf("%c",&(person[i].sex));
printf("Enter the person's Birth Date (DD/MM/YYYY): ");
scanf("%d/%d/%d",&(person[i].day),&(person[i].month),&(person[i].year));
}
database=fopen("mycensus.dat","wb");
fwrite(person,sizeof(struct person),10,database);
fclose(database);
return(0);
}
Errors:
bash-3.00$ gcc -o readdata -Wall readdatabase.c
readdatabase.c: In function `main':
readdatabase.c:12: error: invalid application of `sizeof' to an incomplete type