Hello, Im new to programming and Im taking an introductory programming course at my university. It is our last assignment for the semester and it is giving me quite a bit of trouble and I was wondering if anyone could help me out.
Basically, I am given a file of an unspecified number of hockey players with all their stats and I need to scan the file for all the names, info etc then calculate their points-per-game and print it back so its sorted from highest ppg to lowest ppg.
The file looks something like:
Players Team pos GP G A P
Daniel Sedin VAN L 73 38 55 93
Steven Stamkos TBL C 72 43 43 86
Henrik Sedin VAN C 73 18 68 86
Martin StLouis TBL R 72 26 59 85
Corey Perry ANA R 72 39 40 79
Alex Ovechkin WSH L 73 29 48 77
Henrik Zetterberg DET L 73 21 52 73
Jonathan Toews CHI C 70 30 42 72
Anze Kopitar LAK C 73 25 47 72
Jarome Iginla CGY R 75 33 38 71
Patrick Sharp CHI L 71 34 34 68
Brad Richards DAL C 62 25 42 67
Teemu Selanne ANA R 63 22 45 67
Sidney Crosby PIT C 41 32 34 66
the problem I am having is I dont't really know how to tackle scanning both strings and integers at the same time into multiple arrays..
i tried something like:
Code:
while (fscanf(data_file, "%10s %10s %3s %c %d %d %d %d", &first_name[i], &last_name[i], &team[i],
&position[i], &games_played[0][i], &goals[1][i], &assissts[2][i], &points[3][i]) != EOF) {
fscanf(data_file, "%10s %10s %3s %c %d %d %d %d", &first_name[i], &last_name[i], &team[i],
&position[i], &games_played[0][i], &goals[1][i], &assissts[2][i], &points[3][i]);
i = i + 1;
index[i] = i;
numPlayers = i;
}
for (i = 1; i < numPlayers; i++) {
printf("%s, %s %s %c %d %d %d %d %d\n", last_name[i], first_name[i], team[i],
position[i], games_played[0][i], goals[1][i], assissts[2][i], points[3][i]);
}
but it doesnt work. it will print SOME stuff back, but it either is in the wrong place, it prints out extras or just gets completely messed up.
Can anyone help me figure out how to scan all of this into arrays? I feel once I have that sorted out the rest will be a piece of cake
edit: sorry the data layout is all messed up, i couldnt fix it