#include #include #include typedef struct Golfer { char fname[25]; char lname[25]; int handicap; } Golfer; //return the index of the best golfer int findBest(Golfer golfers[], int numGolfers); int main() { printf("Hello World!\n"); Golfer g; strcpy(g.fname, "Rob"); strcpy(g.lname, "Rosbersts"); g.handicap = 9; printf("%s, %s - %d\n", g.lname, g.fname, g.handicap); Golfer golfers[50]; FILE *fptr; fptr = fopen("golfers.dat", "r"); char buf[BUFSIZ]; int numGolfers = 0; if (fptr == NULL) { printf("Cannot open file!\n"); exit(0); } else { printf("found it!\n"); char fname[25]; char lname[25]; int handicap; while (fscanf(fptr, "%s %s %d", fname, lname, &handicap) != EOF) { printf("reading... %s %s %d\n", fname, lname, handicap); strcpy(golfers[numGolfers].fname, fname); strcpy(golfers[numGolfers].lname, lname); golfers[numGolfers].handicap = handicap; numGolfers++; } for (int i = 0; i < numGolfers; i++) { printf("%s, %s - %d\n", golfers[i].lname, golfers[i].fname, golfers[i].handicap); } } int best = findBest(golfers, numGolfers); printf("%s %s is the best golfer\n", golfers[best].fname, golfers[best].lname); } int findBest(Golfer golfers[], int numGolfers) { int best = 0; for (int i = 1; i < numGolfers; i++) { if (golfers[best].handicap > golfers[i].handicap) best = i; } return best; }