#include #define MAX 4 int main() { // assuming MAX contestants int sum[MAX]; // record the results for each contestant int line[MAX]; // one input line from the judge (single judge input) int judgeCount = 0; // not really needed FILE* inFilePtr = NULL; int c; char *names[MAX] = {"david", "bob", "mary", "jane"}; // reset to 0 for (c=0; c < MAX; c++) { sum[c] = 0; } inFilePtr = fopen("judge.dat", "r"); if (inFilePtr == NULL) { fprintf(stderr, "check your judge.dat file..."); return -1; } // read file while(!feof(inFilePtr)) { for (c=0; c < MAX; c++) { fscanf(inFilePtr, "%d", &line[c]); sum[c]+= line[c]; // printf("%s has %d votes.\n", names[c], sum[c]); } } fclose(inFilePtr); // report the results for (c=0; c < MAX; c++) { printf("%s has %d votes.\n", names[c], sum[c]); } return 0; }