#include
#include
FILE * open_file() {
char out_file[100];
FILE *input = NULL;
while (input == NULL) {
printf("Please enter input file name:");
gets(out_file);
input = fopen(out_file, "r");
}
return input;
}
void process_file(FILE *input) {
char data[6200][200];
char a[6200][50+1];
char bb[6200][6+1];
char cc[6200][3+1];
char d[6200][25+1];
char ee[6200][4+1];
int c[6200];
int e[6200];
int b[6200];
int n = 0;
int i, j;
while (fgets(data[n], 200, input)) {
strncpy(a[n], data[n], 51);
strncpy(bb[n], data[n] + 51, 6);
strncpy(cc[n], data[n] + 58, 3);
strncpy(d[n], data[n] + 62, 25);
strncpy(ee[n], data[n] + 88, 4);
c[n] = 0;
for (i = 0; i max) {
max = c[i];
high = i;
}
m++;
}
}
printf("The count of records in the input file which match the user’s criteria: %d\n", m);
double t = m * 100.0 / n;
printf("The average percentage for those records: %.1f\n", t);
printf("The country with the lowest percentage for those records:\n");
printf("%s %d\n", a[low], c[low]);
printf("The country with the highest percentage for those records:\n");
printf("%s %d\n", a[high], c[high]);
fclose(input);
}
int main() {
FILE *input = open_file();
process_file(input);
return 0;
}