I need help debugging this program... It doesn't print what I loaded successfully... I'm using borland v4(something)... can someone help me?
I need help debugging this program... It doesn't print what I loaded successfully... I'm using borland v4(something)... can someone help me?
Last edited by drdroid; 04-02-2002 at 01:36 PM.
Looks good to me. Nice job!
ahh can you edit your post and use the code tags? you know? ["code"] and ["/code"]? It will make that a lot easier for us to read over.
"only two things are infinite, the universe and human stupidity, and im not sure about the former." - albert einstein
int save()
{
int lp2=5;
while(lp2!=0)
{
char nme[100];
int at;
int gp;
int lvl;
int hp;
if(lp2==5)
{
ofstream a_file("nme.txt", ios::trunc);
a_file << nme;
//etc
The above code indicates that save() is not to be passed any parameters. It is designed to save information to one of a variety of files, based on what type of information it is. Unfortunately, the variables being written to file, nme in the snippet above, is never intialized with data. I suspect you want to pass nme obtained in main() to save() so it can be stored in file. If you do that, then drop the line char nme[100]; from the above snippet, as you don't need it, and in fact, it can screw things up if you aren't careful.
Similar arguments can be made for all the other variables as well.
Also the lines:
main:
;
should be removed, from what I can tell.
When I remove the creation of the variables it comes up with errors: undefined symbol nme etc.
The code is updated below:
Last edited by drdroid; 04-03-2002 at 04:00 PM.
This code(above) doesn't work... it comes up with error messages and I can't figure out what's wrong with them... Can someone compile this, and help me out?
void main()
{
main:
;
remove the last two lines of the above.
==================================
Use one if and the rest else ifs in save()
==================================
Use ios::app rather than ios::trunc
==================================
I suggest declaring a single ofstream in main and passing it as a reference to save() in addition to the other parameters. Then open and close it as needed like this:
void save(ofstream & a_file, //etc)
{
int lp2=5;
while(lp2!=0)
{
if(lp2==5)
{
a_file.open("nme.txt", ios::app);
a_file << nme;
a_file.close();
}
else if(lp2==4)
{
a_file.open("lvl.txt", ios::app);
a_file << lvl;
a_file.close();
}
//etc;
int main()
{
ofstream a_file;
//etc.
================================
post the first couple of error messages you get when compiling. After the first couple, the rest don't mean much oftentimes. So I usually correct the first couple then recompile.