Code:
STATISTICS stats[12] =
{
{"Anaheim Arrays", 0.0, 0.0, .000, 0, 0},
{"Pittsburg Pointers", 0.0, 0.0, .000, 0, 0},
{"Indianapolis Integers", 0.0, 0.0, .000, 0, 0},
{"Denver Double", 0.0, 0.0, .000, 0, 0},
{"Sacremento Strings", 0.0, 0.0, .000, 0, 0},
{"Vancouver Vectors", 0.0, 0.0, .000, 0, 0},
{"Minnesota Mallocs", 0.0, 0.0, .000, 0, 0},
{"Fargo Floats", 0.0, 0.0, .000, 0, 0},
{"Chicago Callocs", 0.0, 0.0, .000, 0, 0},
{"Dallas Delimeters", 0.0, 0.0, .000, 0, 0},
{"San Diego Structs", 0.0, 0.0, .000, 0, 0},
{"Washington Destroyers", 0.0, 0.0, .000, 0, 0}
};
and here is the function that writes my data. The sA array is only used to change the scheduled games based on the variable week.
Code:
void schedule(STATISTICS stats[]) { //http://www.crowsdarts.com/roundrobin/sched12.html
FILE *f;
int sA[12], week = 0, runsPerGameA = 0, runsPerGameB = 0, runsAgainstA = 0, runsAgainstB = 0;
int index, a = 0, b = 1, i = 0;
f = fopen("Cleague.bin", "wb");
week = stats[0].wins + stats[0].losses + 1;
switch (week) {
case 1:
sA[0]=0, sA[1]=1, sA[2]=2, sA[3]=3, sA[4]=4, sA[5]=5, sA[6]=6, sA[7]=7, sA[8]=8, sA[9]=9, sA[10]=10, sA[11]=11;
break;
case 2:
sA[0]=10, sA[1]=0, sA[2]=1, sA[3]=2, sA[4]=3, sA[5]=4, sA[6]=5, sA[7]=6, sA[8]=7, sA[9]=8, sA[10]=11, sA[11]=9;
break;
case 3:
sA[0]=0, sA[1]=2, sA[2]=3, sA[3]=1, sA[4]=4, sA[5]=6, sA[6]=7, sA[7]=5, sA[8]=9, sA[9]=10, sA[10]=8, sA[11]=11;
break;
case 4:
sA[0]=5, sA[1]=0, sA[2]=1, sA[3]=10, sA[4]=6, sA[5]=3, sA[6]=2, sA[7]=9, sA[8]=8, sA[9]=4, sA[10]=11, sA[11]=7;
break;
case 5:
sA[0]=9, sA[1]=0, sA[2]=1, sA[3]=8, sA[4]=2, sA[5]=10, sA[6]=3, sA[7]=5, sA[8]=7, sA[9]=4, sA[10]=6, sA[11]=11;
break;
case 6:
sA[0]=0, sA[1]=8, sA[2]=9, sA[3]=1, sA[4]=3, sA[5]=7, sA[6]=6, sA[7]=2, sA[8]=10, sA[9]=4, sA[10]=11, sA[11]=5;
break;
case 7:
sA[0]=0, sA[1]=3, sA[2]=5, sA[3]=1, sA[4]=2, sA[5]=7, sA[6]=6, sA[7]=9, sA[8]=8, sA[9]=10, sA[10]=4, sA[11]=11;
break;
case 8:
sA[0]=0, sA[1]=6, sA[2]=7, sA[3]=1, sA[4]=8, sA[5]=2, sA[6]=4, sA[7]=9, sA[8]=10, sA[9]=5, sA[10]=11, sA[11]=3;
break;
case 9:
sA[0]=4, sA[1]=0, sA[2]=1, sA[3]=6, sA[4]=7, sA[5]=9, sA[6]=8, sA[7]=5, sA[8]=10, sA[9]=3, sA[10]=2, sA[11]=11;
break;
case 10:
sA[0]=7, sA[1]=0, sA[2]=10, sA[3]=6, sA[4]=4, sA[5]=2, sA[6]=9, sA[7]=5, sA[8]=3, sA[9]=8, sA[10]=11, sA[11]=1;
break;
case 11:
sA[0]=8, sA[1]=6, sA[2]=1, sA[3]=4, sA[4]=5, sA[5]=2, sA[6]=7, sA[7]=10, sA[8]=3, sA[9]=9, sA[10]=0, sA[11]=11;
break;
case 12:
printf("\t\tThe Season is over. Here are the final standings\n");
showStats(stats, -1);
break;
}
printf("Please enter the results from the week %i games.\n\n\n", week);
printf("The home team %s plays the visiting %s\n", stats[sA[0]].teams, stats[sA[1]].teams);
printf("The home team %s plays the visiting %s\n", stats[sA[2]].teams, stats[sA[3]].teams);
printf("The home team %s plays the visiting %s\n", stats[sA[4]].teams, stats[sA[5]].teams);
printf("The home team %s plays the visiting %s\n", stats[sA[6]].teams, stats[sA[7]].teams);
printf("The home team %s plays the visiting %s\n", stats[sA[8]].teams, stats[sA[9]].teams);
printf("The home team %s plays the visiting %s\n", stats[sA[10]].teams, stats[sA[11]].teams);
pause;
cls;
for (index = 0; index < 6; index++){
printf("Enter the runs scored for %s :", stats[sA[a]].teams);
scanf("%i", &runsPerGameA);
printf("Enter the runs scored for %s: ", stats[sA[b]].teams);
scanf("%i", &runsPerGameB);
runsAgainstA = runsPerGameB;
runsAgainstB = runsPerGameA;
if (runsPerGameA < runsPerGameB){
stats[sA[a]].losses += 1;
stats[sA[b]].wins += 1;
}
else {
stats[sA[a]].wins += 1;
stats[sA[b]].losses += 1;
}
stats[sA[a]].runsScored += runsPerGameA;
stats[sA[b]].runsScored += runsPerGameB;
stats[sA[a]].runsAgainst += runsAgainstA;
stats[sA[b]].runsAgainst += runsAgainstB;
if (stats[sA[a]].wins == 0){
stats[sA[a]].pct = .000;
}
else {
stats[sA[a]].pct = stats[sA[a]].wins / (stats[sA[a]].losses + stats[sA[a]].wins);
}
if (stats[sA[b]].wins == 0){
stats[sA[b]].pct = .000;
}
else {
stats[sA[b]].pct = stats[sA[b]].wins / (stats[sA[b]].losses + stats[sA[b]].wins);
}
a += 2;
b += 2;
}
if (!f)
{
cls;
printf("Unable to open file!");
pause;
exit (0);
}
for (i = 0; i < 12; i++){
fwrite(&stats[i], sizeof(stats[i]), 1, f);
}
fclose(f);
}
Can someone tell me if this is where my problem lies or is it more likely at a different point in the program where I am reading from the file.