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!
Printable View
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!
You mean like this:Quote:
Originally Posted by joerules22
Code:int main()
{
char *p = 0;
*p = 'x';
}
The program above compiles with no errors, and it can crash when you run it.Quote:
All it does is crash sooner than it opens please tell me if anyone has ever had this happen.
So show your code.
Regards,
Paul McKenzie
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;
}
please help..
Hmm aside from that you didn't initialize your variables, the code is fine.
Please check your compiler and project settings.
-Andy
whenever i open any exe that opens in command prompt it crashes... i just found this out... any ideas?
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...
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? :(?
What do you mean by "crash" ? What error message gets shown ?
it just comes up for a milisecond and poof is gone.
Fix the uninitialized variables and run the program from the command-line.
Regards,
Paul McKenzie
EVEN this program wont work!
#include <iostream>
using namespace std;
int main ()
{
cout << "Hello World!";
return 0;
}
IS NOT A CRASHQuote:
it just comes up for a milisecond and poof is gone.
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:
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
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?Quote:
Originally Posted by TheCPUWizard
Regards,
Paul McKenzie
http://s30.photobucket.com/albums/c3...nt=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...
So I guess this means the problem has been solved.
Regards,
Paul McKenzie
Which is what it's supposed to do.Quote:
Originally Posted by joerules22
What made you think that the main() function isn't supposed to terminate?
Regards,
Paul McKenzie
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.
the window wont even stick around long enough for me to read it..
what about 10 thousand frames per second? can my monitor display all those frames? pQuote:
Originally Posted by TheCPUWizard
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
It looks like you do not know how C++ programs are supposed to work.Quote:
Originally Posted by joerules22
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
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...
Quote:
and if i run it in comand prompt it will not accept any input from me
This program does not EXPECT any input.Code:#include <iostream>
using namespace std;
int main ()
{
cout << "Hello World!";
return 0;
}
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:
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.
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:
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.
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
Code:cin.sync(); // add these
cin.ignore(); // two lines
return 0;
you are my new god! :p thank you sooo much! i think i understand now!