Saturday, May 22, 2010

My C+ program's crash !?

I wanted to make a simple c+ program with the following :





#include %26lt;stdio.h%26gt;





int main()


{


int this_is_a_number;





printf( "Please enter a number: " );


scanf( "%d", %26amp;this_is_a_number );


printf( "You entered %d", this_is_a_number );


getchar();





return 0;


}





When i compile any program and run it , its simply crashes .


I am using Windows Xp , tryied to run the applications in Windows 95-98 but not luck.


Thing is i need to create these for the MSDOS.. so ....





Anyways anything will help . Thx

My C+ program's crash !?
I don't know what to tell you. I compiled this on my Linux box verbatim and it works just fine. It is strict, standard C code so it should compile andrun on all platforms.





What do you mean by the program crashes? Does a DOS prompt come up and just disappear?





I think your C code is fine. If I had to guess, I'd say that you are making a mistake a lot of beginning Windows programmers seem to make. You are probably double clicking your compiled program from a directory folder. The program isn't crashing, it is just running so fast that you cannot see the execution. So the prompt is probably popping up, you are entering the number and the program is working fast enough where you cannot see the result.





I suggest opening a DOS prompt first and cd-ing to the directory where your compiled executable is and running it from there.
Reply:Perhaps your instructor would be better qualified to help you, since he or she is the one who assigned the problem in the first place.





I see the problem, but if I just give you the answer, you won't learn much.





I wish you the very best of luck, but I think you will grow as a programmer if you "struggle" through this, just like a butterfly struggling to leave the cocoon develops strong wings, but a butterfly who has the cocoon opened for her (or him) is weak, can not fly, and dies within minutes of emerging.


No comments:

Post a Comment