This is the code I have... how do I make it so I can access the info in the read_file function in my print_report function?
Code:#include <stdio.h> #define MAXRECORDS 4 struct record { char gender; int age; int lead; }; void read_file(); void print_report(); int main() { read_file(); print_report(); } void read_file() { FILE *fpin; int i; struct record rec[MAXRECORDS]; fpin = fopen("custsurvey.dat", "r"); if(fpin == NULL) { printf("Error opening file"); } else { for(i = 0; i < MAXRECORDS; i++) fscanf(fpin, " %c %d %d", &rec[i].gender, &rec[i].age, &rec[i].lead); } fclose(fpin); } void print_report() { FILE *fpout; fpout = fopen("surveyreport.txt", "w"); if(fpout == NULL) { printf("Error opening file"); } else { printf("%c %d %d", rec[0].gender, rec[0].age, rec[0].lead); } }



LinkBack URL
About LinkBacks



