I need to write a program that essentially reads in numbers from atext file and
ID: 3617315 • Letter: I
Question
I need to write a program that essentially reads in numbers from atext file and prints their sum. The numbers correspond to apersons, or multiple persons, golf scores. The text file would have at least 3 lines -- The first linewould be the number of golfers, the second line would be the parscore for each of the holes, and the 3rd line would be the golfersscore for each hole.The file would look something like this if there were 2golfers:
2 3 4 4 4 4 5 5 3 3 4 4 4 4 4 5 3 3 4 4 4 5 4 6 4 5 6 3 4 4 4 5 4 3 3 5 4 2 3 4 4 4 5 5 3 3 4 4 4 4 4 4 3 3 4
I realize that I would have to store the numbers in anarray, and possibly use a for loop to read each of the scores inthe an array? and then sum them to print the first golfersscore and then the second golfers score.
I really don't understand FILE I/O too well
What i don't understand how to do is read the numbers from thefile since the numbers have spaces in between then and they are ina line. I also don't understand how I'm supposed to make theprogram read each individual line and do a specific function.
I also don't know which of these I should use. fscanf,fgets,
as far as I would know to go is......
File* fin
fin = fopen("scores.txt", "r");
... ... ...
fclose(fin); system("PAUSE") return 0; The text file would have at least 3 lines -- The first linewould be the number of golfers, the second line would be the parscore for each of the holes, and the 3rd line would be the golfersscore for each hole.
The file would look something like this if there were 2golfers:
2 3 4 4 4 4 5 5 3 3 4 4 4 4 4 5 3 3 4 4 4 5 4 6 4 5 6 3 4 4 4 5 4 3 3 5 4 2 3 4 4 4 5 5 3 3 4 4 4 4 4 4 3 3 4
I realize that I would have to store the numbers in anarray, and possibly use a for loop to read each of the scores inthe an array? and then sum them to print the first golfersscore and then the second golfers score.
I really don't understand FILE I/O too well
What i don't understand how to do is read the numbers from thefile since the numbers have spaces in between then and they are ina line. I also don't understand how I'm supposed to make theprogram read each individual line and do a specific function.
I also don't know which of these I should use. fscanf,fgets,
as far as I would know to go is......
File* fin
fin = fopen("scores.txt", "r");
... ... ...
fclose(fin); system("PAUSE") return 0;