I have an array of structs where they are sorted by ID and there are duplicate entries of that ID within the array. Each struct in the array has a number of points assosiated with it and I want to find the total number of points for each ID. I want to remove any duplicates and store their total points value in a single struct reducing the size of my array.
typedef struct boat_data {
int ID;
int time_to_complete_race; //This can be ignored
int points;
} boat_node;
typedef boat_node boat_ptr;
The current code that I have made doesn't seem to work as intended. tot_boats
is the number of boats and tot_members
is the number of members that have been found (by this I mean the number of non-duplicate ID's present). I have two array structs where the final_boat_scores
is of the size of the number of members present and I want to store the ID
value and the points
value
for(int boat = 0; boat < (total_boats - tot_members); boat++) {
for (int next_boat = 0; next_boat < (total_boats - tot_members); next_boat++) {
if (boat_scores[boat].ID == boat_scores[next_boat].ID) {
final_boat_scores[boat].ID = boat_scores[next_boat].ID;
final_boat_scores[boat].points += boat_scores[next_boat].points;
break;
}
}
}