Program crashes when not loaded from inside Visual C++ 6.0

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Deviate
    New Member
    • Aug 2007
    • 11

    Program crashes when not loaded from inside Visual C++ 6.0

    Hi guys, my first post here, im desperately in need of help! :)

    When i am running Visual C++ 6.0 and have my .cpp file opened, i compile, build and run the program, it all works fine. But if i close Visual and try to run the program .exe from the Debug folder, it crashes half way through the program :( i dont understand why ..i will refrain from posting the code for my program since its quite long and messy.. hope anyone knows a solution.
  • sicarie
    Recognized Expert Specialist
    • Nov 2006
    • 4677

    #2
    Originally posted by Deviate
    Hi guys, my first post here, im desperately in need of help! :)

    When i am running Visual C++ 6.0 and have my .cpp file opened, i compile, build and run the program, it all works fine. But if i close Visual and try to run the program .exe from the Debug folder, it crashes half way through the program :( i dont understand why ..i will refrain from posting the code for my program since its quite long and messy.. hope anyone knows a solution.
    Do you know where it crashes? Try using print statements as debug statements (ie: cout << "Reached 'double calculate_avera ge()' function\n";), you can see where it goes down.

    I'm guessing you coded a relative path, and then are executing from a different location, but that's just a wild guess with the information provided...

    Comment

    • Deviate
      New Member
      • Aug 2007
      • 11

      #3
      thanks for a really fast reply! :)

      "I'm guessing you coded a relative path, and then are executing from a different location, but that's just a wild guess with the information provided..."

      -sorry, im not even sure i know what that means :o when i first started making the program i did the usual "win32 console application + C++ source file thing" and then chose the desktop as the destination to save it. So there is a folder for my program and inside it is the .exe for my program which i just double click, and thats when it crashes half way through. But when i double click the .cpp file and compile+build+r un it doesnt crash :/ very strange ..and about using cout<< to be able to see exactly where it crashes, thx for the advice, will try that, probably tomorrow since ive had it for today with this ;) hehe ..but as far as i can see its like this : (in the program) "to solve using QR, press 1:
      to solve using normal equations, press 2:"

      So when i press 1 or 2, it crashes directly after i press enter.. but like ive said when its loaded from inside Visual C++, it proceeds to calculate using the chosen method from above, like it should.. anyways, this is getting long :P

      thx to anyone who has more advice for me!

      Comment

      • weaknessforcats
        Recognized Expert Expert
        • Mar 2007
        • 9214

        #4
        I suspect the program you are executing manually is not the program being compiled by VC 6.0.

        Do this:

        1) Create new C++ Console Application project on a new path YOU SELECT.
        2) Move your .cpp and .h files to that project folder
        3) Add the .cpp files to the project
        4) Build the project
        5) Execute the code in VC 6.0
        6) Navigate to the Debug folder for that project
        7) Execute the .exe by double clicking

        Comment

        • Deviate
          New Member
          • Aug 2007
          • 11

          #5
          Thanks for a swift reply :)

          But hmm! I did as you said, created a new console application, added the .cpp file from the old folder, built and executed from within VC, which worked. But when i closed down VC and launched the .exe from the new folder, the same problem, crashes at the same place! :S Now i was wondering, could it be that the program just terminates after its run all the code? I mean, usually when it has finished running, it just says "press any key to continue" . Maybe if i put the whole of main() inside a do/while loop, with the question "do you want to run the program again? y/n : " .. at least thats an easy way to figure out if all the code is actually processed. Because, when the program crashes, there is only cout<< to the screen, maybe it actually does the whole cout<< and then terminates, but does it too fast for me to see it ..

          Will keep you guys posted when i try adding the do/while loop! Thx to both for the help :)

          Comment

          • Deviate
            New Member
            • Aug 2007
            • 11

            #6
            WOOP! Sorry for the double post, but i JUST wanted to say that i was indeed right ! :) i just added the do/while around all the code in main() which then requires a y/n answer, this keeps the program from terminatin after the code has been run :) so yeah..

            This thread can be closed now, got my answer :) Thx to all who posted! What a beginners error :/ *blush* hehe :p

            Comment

            • weaknessforcats
              Recognized Expert Expert
              • Mar 2007
              • 9214

              #7
              Hold on there a minute.

              Originally posted by Deviate
              I mean, usually when it has finished running, it just says "press any key to continue" .
              You didn't mention this before.

              The "press any key to continue" is provided by Visual Studio at the end of
              main() when you select Start Without Debugging.

              That black window might look like the command interpreter, but it's not. It's just a black window. Notice the Command Interpreter has a prompt: C:\>.

              Your crash might he related to memory corruption as cleanup from your program can be deferred until after the closing brace of main().

              Indeed, when main() finishes, your program is done.

              You never really said how the program crashed. Like what was the error?

              Comment

              • Deviate
                New Member
                • Aug 2007
                • 11

                #8
                sorry about that cats! I wasnt aware *blush* i sort of expected the "press any key to continue part" to also be there when i launched the .exe and that was essentially the mistake.. in fact my program didnt -crash- , it actually just was finished.. thats why adding the do/while around it solved the problem .. so sorry for not posting that info before, that was just due to my lack of basic knowledge of Visual :p apologies for that hehe..

                Comment

                • weaknessforcats
                  Recognized Expert Expert
                  • Mar 2007
                  • 9214

                  #9
                  No apologies required.

                  All of us, at one time or another, have just looked at the screen and said: "What????.. ..."

                  Comment

                  • Banfa
                    Recognized Expert Expert
                    • Feb 2006
                    • 9067

                    #10
                    Originally posted by weaknessforcats
                    No apologies required.

                    All of us, at one time or another, have just looked at the screen and said: "What????.. ..."
                    Usually first thing every morning when trying to work out what I did yesterday :D

                    Comment

                    • Tops
                      New Member
                      • Jan 2008
                      • 4

                      #11
                      I had just a quick question, what are you using for the loop?
                      I'm new to this C++ and am having the same problem, my program executes way to fast to get the solution and using the code to run again would be perfect.
                      Its just a simple program to find the area of a rectangle.
                      Thanks!

                      Comment

                      Working...