By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
446,194 Members | 888 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 446,194 IT Pros & Developers. It's quick & easy.

Why am I getting an assert failure message with this code?

P: n/a
This function loads info from a binary data file, then loads objects
(currently 23 in the test file). Here is the loading function:

bool UnitDefLoad(char* sFile)
{
UnitDefCleanList(false); // tested. This works.
int iUnitCount = 0;
UNIT_DEF uData; // Theses objects are read from file
ifstream fin(sFile,ios::binary);
if (!fin)
{
return false;
} // end if
else
{
fin.read((char*) &Unit_Def_Node::Arthur, sizeof
(Unit_Def_Node::Arthur));
fin.read((char*) &Unit_Def_Node::iMonth, sizeof
(Unit_Def_Node::iMonth));
fin.read((char*) &Unit_Def_Node::iDay, sizeof
(Unit_Def_Node::iDay));
fin.read((char*) &Unit_Def_Node::iYear, sizeof
(Unit_Def_Node::iYear));
fin.read((char*) &Unit_Def_Node::Description, sizeof
(Unit_Def_Node::Description));
fin.read((char*) &Unit_Def_Node::iVersion, sizeof
(Unit_Def_Node::iVersion));
fin.read((char*) &Unit_Def_Node::iBuild, sizeof
(Unit_Def_Node::iBuild));
fin.read((char*) &iUnitCount, sizeof (iUnitCount));

for (int iCount = 1; iCount < iUnitCount; iCount++)
{
fin.read((char*) &uData, sizeof (uData));
UnitDefADD(uData);
cout << "Number of Unit_Def_Nodes: " << iUnitsDefined << "\n";

}; // end for
};
fin.close();
return true;
};
I believe the problem is the
fin.read((char*) &uData, sizeof (uData));
in the for loop. I have 23 UNIT_DEF objects saved in the file. After
the 23rd object is loaded, it exits the loop and crashes... if I
comment out the above line, the program works fine. Is there
something wrong with my syntax?
Jul 22 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
"Skywise" <th********@houston.rr.com> wrote in message
news:21**************************@posting.google.c om...
This function loads info from a binary data file, then loads objects
(currently 23 in the test file). Here is the loading function:

bool UnitDefLoad(char* sFile)
{
UnitDefCleanList(false); // tested. This works.
int iUnitCount = 0;
UNIT_DEF uData; // Theses objects are read from file
ifstream fin(sFile,ios::binary);
if (!fin)
{
return false;
} // end if
else
{
fin.read((char*) &Unit_Def_Node::Arthur, sizeof
(Unit_Def_Node::Arthur));
fin.read((char*) &Unit_Def_Node::iMonth, sizeof
(Unit_Def_Node::iMonth));
fin.read((char*) &Unit_Def_Node::iDay, sizeof
(Unit_Def_Node::iDay));
fin.read((char*) &Unit_Def_Node::iYear, sizeof
(Unit_Def_Node::iYear));
fin.read((char*) &Unit_Def_Node::Description, sizeof
(Unit_Def_Node::Description));
fin.read((char*) &Unit_Def_Node::iVersion, sizeof
(Unit_Def_Node::iVersion));
fin.read((char*) &Unit_Def_Node::iBuild, sizeof
(Unit_Def_Node::iBuild));
fin.read((char*) &iUnitCount, sizeof (iUnitCount));

for (int iCount = 1; iCount < iUnitCount; iCount++)
{
fin.read((char*) &uData, sizeof (uData));
UnitDefADD(uData);
cout << "Number of Unit_Def_Nodes: " << iUnitsDefined << "\n";

}; // end for
};
fin.close();
return true;
};
I believe the problem is the
fin.read((char*) &uData, sizeof (uData));
in the for loop. I have 23 UNIT_DEF objects saved in the file. After
the 23rd object is loaded, it exits the loop and crashes... if I
comment out the above line, the program works fine. Is there
something wrong with my syntax?


I don't see anything wrong with your syntax, but the syntax is not where the
problem lies. If you don't supply a complete example, it is hard for anyone
to help you. I doubt that anyone else browsing this group knows what
Unit_Def_Node is, what a UNIT_DEF is, what UnitDefADD does, what the file
contains, etc. The best advice you can get from your current post is "use a
debugger".

--
David Hilsee
Jul 22 '05 #2

P: n/a

"David Hilsee" <da*************@yahoo.com> wrote in message
news:ob********************@comcast.com...
<snip>
I don't see anything wrong with your syntax, but the syntax is not where the problem lies. If you don't supply a complete example, it is hard for anyone to help you. I doubt that anyone else browsing this group knows what
Unit_Def_Node is, what a UNIT_DEF is, what UnitDefADD does, what the file
contains, etc. The best advice you can get from your current post is "use a debugger".


The second best advice would be to check to see if the calls to read()
actually succeed. The third best would be to use a text file instead of a
binary file so it's easier to follow.

--
David Hilsee
Jul 22 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.