Click to See Complete Forum and Search --> : every single program crashes help me please!!


joerules22
February 15th, 2007, 07:10 PM
I need help everytime i compile the code it says no errrors or anything. All it does is crash sooner than it opens please tell me if anyone has ever had this happen. I use bloodshed dev C++. its driving my a bit insane somone!

Paul McKenzie
February 15th, 2007, 07:14 PM
I need help everytime i compile the code it says no errrors or anything.
You mean like this:

int main()
{
char *p = 0;
*p = 'x';
}

All it does is crash sooner than it opens please tell me if anyone has ever had this happen.The program above compiles with no errors, and it can crash when you run it.

So show your code.

Regards,

Paul McKenzie

joerules22
February 15th, 2007, 07:36 PM
Im just learning c++ this is what i just made and it does the same.

#include <iostream>
using namespace std;

int main ()
{
int a;
int b;
int result;

cout << "enter your addition equation";

result = a + b;

cout << result;

return 0;
}

joerules22
February 15th, 2007, 08:07 PM
please help..

namezero111111
February 15th, 2007, 08:14 PM
Hmm aside from that you didn't initialize your variables, the code is fine.

Please check your compiler and project settings.

-Andy

joerules22
February 15th, 2007, 08:16 PM
whenever i open any exe that opens in command prompt it crashes... i just found this out... any ideas?

namezero111111
February 15th, 2007, 08:22 PM
You mean if you start cmd.exe and then open, let's say "calc.exe" ?

What's your operating system? It is likely that the O/S is at fault here...

joerules22
February 15th, 2007, 08:27 PM
it just seems to be programs that i have compiled. Ive downloaded a bunch of soucecode everything i have compiled has crashed. I have another computer and these same programs work. My OS is XP what the hell is going on? :(?

Philip Nicoletti
February 15th, 2007, 08:45 PM
What do you mean by "crash" ? What error message gets shown ?

joerules22
February 15th, 2007, 08:47 PM
it just comes up for a milisecond and poof is gone.

Paul McKenzie
February 15th, 2007, 08:49 PM
Fix the uninitialized variables and run the program from the command-line.

Regards,

Paul McKenzie

joerules22
February 15th, 2007, 08:52 PM
EVEN this program wont work!


#include <iostream>
using namespace std;

int main ()
{
cout << "Hello World!";
return 0;
}

TheCPUWizard
February 15th, 2007, 09:03 PM
it just comes up for a milisecond and poof is gone.


IS NOT A CRASH

If you open a Command Prompt Window (so you get a C:> prompt), navigate to the directory with the .exe, and run the exe from the command line, Wjat Happens?

ps: The humnan eye is not capable of recognizing something that take only a millisecond. And neither is your computer monitor, so obviously your statement is also wrong. :eek:

Paul McKenzie
February 15th, 2007, 09:04 PM
Did you do what I stated? Open a command window, go to where the exe was created, and run it from the command line.

Do *not* run it by clicking on it in Windows Explorer, or from the Dev-C++ "run" option or anything like that.

Regards,

Paul McKenzie

Paul McKenzie
February 15th, 2007, 09:09 PM
IS NOT A CRASH

If you open a Command Prompt Window (so you get a C:> prompt), navigate to the directory with the .exe, and run the exe from the command line, Wjat Happens?It's amazing how the simplest thing, i.e. just go to the directory and type in the name of the exe seems to escape so many of these new programmers. I mean, isn't that the way they're taught to run any compiled program?

Regards,

Paul McKenzie

joerules22
February 15th, 2007, 09:11 PM
http://s30.photobucket.com/albums/c307/joerules22/?action=view&current=error-1.jpg please look at that and tell me what you guys think is the problem... the program doesnt stay active it just ends...

Paul McKenzie
February 15th, 2007, 09:13 PM
So I guess this means the problem has been solved.

Regards,

Paul McKenzie

Paul McKenzie
February 15th, 2007, 09:14 PM
http://s30.photobucket.com/albums/c307/joerules22/?action=view&current=error-1.jpg please look at that and tell me what you guys think is the problem... the program doesnt stay active it just ends...Which is what it's supposed to do.

What made you think that the main() function isn't supposed to terminate?

Regards,

Paul McKenzie

joerules22
February 15th, 2007, 09:16 PM
no wait!... whenever i compile and run ANYTHING (stuff that isnt supposed to end) it just ends after it displays the text. i mean the window disapears.

joerules22
February 15th, 2007, 09:21 PM
the window wont even stick around long enough for me to read it..

Mitsukai
February 15th, 2007, 09:23 PM
IS NOT A CRASH

If you open a Command Prompt Window (so you get a C:> prompt), navigate to the directory with the .exe, and run the exe from the command line, Wjat Happens?

ps: The humnan eye is not capable of recognizing something that take only a millisecond. And neither is your computer monitor, so obviously your statement is also wrong. :eek:
what about 10 thousand frames per second? can my monitor display all those frames? p

namezero111111
February 15th, 2007, 09:23 PM
That's why you have to run it from the command line as someone said earlier.

Or, you could add a getch() at the end of main before it returns.

-Andy

Paul McKenzie
February 15th, 2007, 09:27 PM
no wait!... whenever i compile and run ANYTHING (stuff that isnt supposed to end) it just ends after it displays the text. i mean the window disapears.It looks like you do not know how C++ programs are supposed to work.

First, the main() function terminates when it exits. Terminating main() means that the program terminates. Nothing makes a program "run forever", unless you make it run forever by introducing a loop, or some other programming method to keep the program running.

Second, a console window can't just "disappear" if you opened the console window yourself and ran the program you posted.

Why not attach one of these exe files, so as to prove that you are doing something wrong, or post one of these C++ programs that's supposed to "run forever". I bet

1) The program does not close the console window, and

2) The program was not programmed to "run forever" as you claim it's supposed to.

Regards,

Paul McKenzie

joerules22
February 15th, 2007, 09:33 PM
not run forever thats not what i mean... once i execute the program the window opens and disapears... and if i run it in comand prompt it will not accept any input from me i guess that was what i was trying to get at. you have to realize this is very very hard to describe...

TheCPUWizard
February 15th, 2007, 09:41 PM
and if i run it in comand prompt it will not accept any input from me



#include <iostream>
using namespace std;

int main ()
{
cout << "Hello World!";
return 0;
}


This program does not EXPECT any input.

Even if english is not your first language, please take the time to re-read what you are posting a few times before hitting submit. :rolleyes:

joerules22
February 15th, 2007, 09:42 PM
ok im going to take everything u guys have said hookline and sinker and read a bit more on c++ b4 i come back and drive everyone insane on this subject :) ill try to deal with it.

TheCPUWizard
February 15th, 2007, 09:44 PM
An excellent idea. After you have given it some though, please come back and let us know how it is going.

Good Luck :wave: :thumb:

joerules22
February 15th, 2007, 09:53 PM
just one more thing. I have done this b4 compiling and runing the programs the window stayed up but just recently it have been disapearing.

Philip Nicoletti
February 15th, 2007, 10:22 PM
You can put the following at the end of the main() function. It will
cause the program to wait for the user to hit the enter key


cin.sync(); // add these
cin.ignore(); // two lines

return 0;

joerules22
February 15th, 2007, 10:26 PM
you are my new god! :p thank you sooo much! i think i understand now!