This is the code I have. To check my struct I put in a printf function and instead of returning
M 60 2
F 42 1
F 12 4
M 26 3
it's returning
F 12 4
1986850018 8M 26 3
0 0
Code:
#include <stdio.h>
#define MAXRECORDS 4
struct record
{
char gender;
int age;
int lead;
};
void read_file();
int main()
{
read_file();
}
void read_file()
{
FILE *fpin;
int i;
struct record rec[MAXRECORDS];
fpin = fopen("custsurvey.dat", "r");
if(fpin == NULL)
{
printf("Error opening file");
}
else
{
while(!feof(fpin))
{
for(i = 0; i < MAXRECORDS; i++)
fscanf(fpin, "%c %d %d", &rec[i].gender, &rec[i].age, &rec[i].lead);
}
}
for(i = 0; i < MAXRECORDS; i++)
printf("%c %d %d", rec[i].gender, rec[i].age, rec[i].lead);
fclose(fpin);
}