| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
Structure in Structure problem - data disappearring
I have a problem that really makes no sense to me. As part of a schedule creation program, i have a structure created for a league, which has an array of team structures which has a schedule structure for each team.
Here are the structures: /////////////////////////////////////// // // // Team Schedule Constructor // // // /////////////////////////////////////// struct teamSchedule { int opposition_ID; int day; int date; int month; int year; }; /////////////////////////////////////// // // // Team Array Constructor // // // /////////////////////////////////////// struct teamRecord { int team_ID; string team_Conference; string team_Home; string team_Name; teamSchedule mySchedule[82]; }; /////////////////////////////////////// // // // League Constructor // // // /////////////////////////////////////// struct leagueRecord { int leagueNumber; int season_ID; string seasonName; string currentDate; string leagueName; string draftDate; string playoffDate; string scheduleDate; teamRecord teams[30]; }; Now I made a 'displayTeamInfo()' function so I could check that all the data gets in there (the part im most concerned about it is the team_ID 's for comparison). Then I made a function to initialise the schedule so that the schedules data is set to 0 for the opposition_ID. But after the schedule is initialised, somehow the team_ID is then set to 0????(I run displayTeamInfo again) There appears no way that this should be set back to 0 by this function. This is the function: int clearTeamSchedules(leagueRecord &myLeague) { for (int i = 0; i < 30; i++) { for (int x = 0; x <= 82; x++) { myLeague.teams[i].mySchedule[x].opposition_ID = 0; } } return 0; } Somehow myLeague.teams[teamnum].team_ID is being reset to 0 by this function. It makes no sense: myLeague.teams[teamnum].team_ID myLeague.teams[teamnum].mySchedule[arraynum].opposition_ID are nothing similar. There is no other code causing this. The call to the routines is like this: displayTeamInfo(myLeague); clearTeamSchedules(myLeague); displayTeamInfo(myLeague); And the output goes like this: --------------------------- Team Info for League 1 --------------------------- Team_Id | Team_Conference --------------------------- 1 1 2 1 3 1 4 1 5 1 6 2 7 2 8 1 9 2 10 2 11 1 12 2 13 2 14 2 15 1 16 1 17 2 18 1 19 2 20 1 21 1 22 1 23 2 24 2 25 2 26 2 27 2 28 1 29 2 30 1 --------------------------- --------------------------- Team Info for League 1 --------------------------- Team_Id | Team_Conference --------------------------- 1 1 0 1 0 1 0 1 0 1 0 2 0 2 0 1 0 2 0 2 0 1 0 2 0 2 0 2 0 1 0 1 0 2 0 1 0 2 0 1 0 1 0 1 0 2 0 2 0 2 0 2 0 2 0 1 0 2 0 1 --------------------------- |
|
#2
|
|||
|
|||
|
I don't see all of your code (specifically how the data is intialized in the first place) but this line looks suspect:
Code:
for (int x = 0; x <= 82; x++) Change it to: Code:
for (int x = 0; x < 82; x++) My guess is that you are running off the ends of your array and that is what is causing your problem. |
![]() |
| Viewing: Dev Articles Community Forums > Programming > C/C++ Help > Structure in Structure problem - data disappearring |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|