I wrote this program for my C class. It basically takes the user to a horse track, display odds on different horses and allows the user to make a bet. Originally, my instructor only wanted us to write the results to a text or binary file, so the past results could be viewed whenever the user wanted.
He recently told us that he wants us to include bubble sort to group the horses in order i.e. horse 1, horse 1, horse 1, horse 1, horse 2, horse 2...etc.
I am sure I can figure out the bubble sort using strcmp(), but he also wants us to display how many times that horse has won the race in the past.
My question is: will I be able to make such a display dealing only with char/string arrays? I don't want to spend my next four hours building a solution that cannot work.
Thanks in advance,
p.s. Here is the function for that part of the program.
void viewWinners() {
FILE *zacksTrackStats;
char horses[MAX_SIZE] = {0};
if ((zacksTrackStats = fopen("zacksTrackStats.txt", "r")) == NULL)
{
perror ("error");
exit (0);
}
while (fgets(horses, sizeof(horses), zacksTrackStats) != NULL)
{
printf ("%s", horses);
}
fclose(zacksTrackStats);
pause;
}