Here is your code, working and cleaned up, minus extra logic/variables etc:
Code:
#include <stdio.h>
int main() {
FILE *ifp;
int ttl_golfers, totalscore, ok, j, i, z, n, p, o;
int tries [8][18];
int score [8][18];
int parscore[18];
ifp = fopen("golf.txt","r");
fscanf(ifp, "%d\n", &ttl_golfers);
printf("%d golfers played on this golf course:\n", ttl_golfers);
for (z=0; z < 18; z++) {
fscanf(ifp, "%d ", &parscore[z]);
parscore[z] = parscore[z];
}
fscanf(ifp,"\n");
for(n=0; n < ttl_golfers; n++) {
for(i = 0; i < 18; i++) {
fscanf(ifp, "%d", &tries[n][i]);
score[n][i] = tries[n][i]- parscore[i];
printf("Golfer #%d's Score: %d\n", n, score[n][i]);
}
fscanf(ifp,"\n");
}
fclose(ifp);
return 0;
}
Please note that this code will ONLY work (and will likely crash) if it is not given a golf.txt file in its current directory that is PERFECTLY formatted, meaning exactly like this:
Code:
8
4 4 3 5 4 3 4 5 6 5 4 4 4 5 5 4 3 3
4 4 3 6 7 4 4 5 4 5 3 5 3 5 7 5 3 2
4 5 3 4 6 5 5 6 3 5 4 6 3 3 5 4 5 3
3 4 5 6 4 4 4 5 5 5 4 5 4 3 3 5 4 3
2 5 5 6 7 6 5 5 4 6 4 5 6 7 5 5 5 5
4 5 6 3 3 5 4 4 3 3 2 5 6 6 5 5 3 3
2 5 3 5 5 5 6 5 4 3 4 5 5 4 4 6 5 5
6 5 4 5 5 3 5 6 5 4 6 5 6 4 4 6 5 4
4 4 5 5 3 3 6 5 4 3 3 5 6 5 3 6 5 4
Note that after each of the lines with 18 digist (not the first line with only one digit) there is a single TRAILING space, this is REQUIRED for it be read correctly.
The slightest mistake, such as 2 extra spaces at the end will result in a file that will not be parsed correctly with the code above.
That is why I mentioned the fgets method as its much more flexible with how the file appears, you could put all kinds of stuff to ignroe comments, extra spacing, etc...with fscanf it is a pain