C/C++ Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
 
Go Back   Dev Articles Community ForumsProgrammingC/C++ Help

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Display Modes
 
Unread Dev Articles Community Forums Sponsor:
  #1  
Old April 4th, 2005, 02:55 AM
MartyConlonJr MartyConlonJr is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jul 2004
Posts: 14 MartyConlonJr User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 3 h 10 m 52 sec
Reputation Power: 0
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
---------------------------

Reply With Quote
  #2  
Old April 4th, 2005, 10:24 PM
BoolBooB BoolBooB is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Feb 2005
Posts: 36 BoolBooB User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 9 h 35 m 42 sec
Reputation Power: 4
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.

Reply With Quote
Reply

Viewing: Dev Articles Community ForumsProgrammingC/C++ Help > Structure in Structure problem - data disappearring


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 5 hosted by Hostway
Stay green...Green IT