My instructor said I wasn't allowed to use a structure as we hadn't been taught it yet. So how am I supposed to read this from a file into an array?
It's set out like this
M 40 6
F 21 2
F 61 5
M 14 1
This is what I have but of course it won't work properly as the first data type is char not int
Code:#include <stdio.h> #define RECORDS 200 #define FIELDS 3 void read_file(); int main() { read_file(); } void read_file() { FILE *fpin; int rec[RECORDS][FIELDS]; int m, n; fpin = fopen("custsurvey.dat", "r"); if(fpin == NULL) { printf("Error opening file"); } else { for(m = 0; m < RECORDS; m++) { for(n = 0; n < FIELDS; n++) { fscanf("%d", &rec[m][n]); } } } fclose(fpin); }