Can someone please help me with my program? I am new to C programming.

Hello,
I was wondering if someone can help me with file input and output.
I basically have golf.txt document that contains data from 8 golfers' scores while playing a game of golf. I used the data in the golf.txt document to create a program that read values from the .txt document and calculates the total score of each golfer. However, now i need to take it a step further and create a program that compares each golfers score to the par score and outputs a value for hole by hole.

The program should output 18 different values for each golfer, where each value will contain (the number of tries- par score= score for that hole) and there are 18 holes in a game of golf so it make sense

Each letter represents each golfers score on each hole. (A for hole 1, B for hole 2..... R for hole 18)

It should look something like this for each golfer:
Golfer #1’s score: A B C D E F G.....R
Golfer #2.................
Golfer #3..................

This should not be too hard because I have it all the data I need in my golf.txt file:

1) Would arrays be the best way to go about completing this program?
2) Would I need a 1d or 2d array to complete this program?
3) If so, I am completely new to arrays! can anyone help me understand how I would set it up? I know that the basic format is something like int numbers [rows][columns]
4) How would I add/ subtract array's positions from each other (for example row 2 column 3 + row 2 column 4) ?

1. Arrays would definitely be useful.
2. I would use a 1d array for the par scores and either a 2d array or an array of structs for the golfer scores. Since you're new to this, I would go with the 2d array for golfer scores.
3. I'd make it an int[# golfers][18]
4. You would use a loop to iterate through each element and add the elements just like any other variable. For example, part of your program might look like this:

Code:

for (i=0; i<18; ++i)
{
score[n][i] = tries[n][i] - par[i];
}

I copied it from the last program in which I passed a parameter, which would have been pre-1989 I guess. - esbo

the bolded code above should be inside the for loop above (its an empty for loop) at this point if you fix that, it does in fact compile....however it segfaults immediately upon running, ill leave that up to you to find out why

As I said prior the printf above sould go into the for loop just above it, right now that for loop does absolutely nothing.

Beyond that however your problems are mainly due to excessive looping and using an inferior method of reading in your records.

Whenever reading data from a file (a flat text file, not binary) you should be using fgets and an appropriate buffer and you should verify the line was read in correctly before attempting to use it or split it up into scores/arrays

Beyond that however your problems are mainly due to excessive looping and using an inferior method of reading in your records.

Whenever reading data from a file (a flat text file, not binary) you should be using fgets and an appropriate buffer and you should verify the line was read in correctly before attempting to use it or split it up into scores/arrays

See I tried to make sure that my code is getting read in correctly but it is not, which is not surprising, but why is this? Even when it is as simple as reading in the first value in the document its reading it as 46 instead of 8