Debug Help

This is a discussion on Debug Help within the C++ Programming forums, part of the General Programming Boards category; I need help debugging this program... It doesn't print what I loaded successfully... I'm using borland v4(something)... can someone help ...

  1. #1
    Student drdroid's Avatar
    Join Date
    Feb 2002
    Location
    Montreal, Quebec
    Posts
    669

    Question Debug Help

    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.

  2. #2
    Unregistered
    Guest
    Looks good to me. Nice job!

  3. #3
    Registered User xds4lx's Avatar
    Join Date
    Nov 2001
    Posts
    630
    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

  4. #4
    Registered User
    Join Date
    Mar 2002
    Posts
    1,595
    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.

  5. #5
    Student drdroid's Avatar
    Join Date
    Feb 2002
    Location
    Montreal, Quebec
    Posts
    669

    Question ???

    When I remove the creation of the variables it comes up with errors: undefined symbol nme etc.

  6. #6
    Student drdroid's Avatar
    Join Date
    Feb 2002
    Location
    Montreal, Quebec
    Posts
    669

    Question ???

    The code is updated below:
    Last edited by drdroid; 04-03-2002 at 04:00 PM.

  7. #7
    Student drdroid's Avatar
    Join Date
    Feb 2002
    Location
    Montreal, Quebec
    Posts
    669

    Compile

    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?

  8. #8
    Registered User
    Join Date
    Mar 2002
    Posts
    1,595
    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.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Binary not built with debug info - why?
    By ulillillia in forum C Programming
    Replies: 15
    Last Post: 12-11-2008, 01:37 AM
  2. makefiles - debug & release?
    By cpjust in forum C Programming
    Replies: 6
    Last Post: 10-26-2007, 05:00 PM
  3. Debug --> Exceptions in Visual Studio 2005
    By George2 in forum C# Programming
    Replies: 1
    Last Post: 08-10-2007, 03:12 AM
  4. Results in Debug and Release mode are different
    By jaro in forum C Programming
    Replies: 11
    Last Post: 05-27-2006, 12:08 PM
  5. Ask about Debug Assert Failed
    By ooosawaddee3 in forum C++ Programming
    Replies: 0
    Last Post: 04-25-2002, 12:07 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21