Sunday, August 2, 2009

Any ideas on how to get my compiler to run properly?

I'm running Dev-C++ and I started out with the infamous "Hello World" program.





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


int main()


{


printf("Hello World\n");


return 0;


}








It compiles just fine, but when I go to run it, the command prompt pops up for a split second and then disappears. Any clue as to why it's doing this, and how I can stop it?

Any ideas on how to get my compiler to run properly?
The window is closing because it ran your program, and your program finished and exited. There's nothing more to do.





Set a break point in your program in order to see what is happening.
Reply:I do not use Dev-C++, but:





1. If it is an IDE, there must be an option to keep console window open after the program has terminated, use that option


AND/OR


2. There are routines in C/C++ to wait for a key-press by the user (e.g., a getch() or a getchar() function or something like that), use that in your program before return 0; statement.
Reply:Rewrite like this





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


int main()


{


printf("Hello World\n");





int dumy = getc(); /* this will stall the program until you press a key */


return 0;


}


No comments:

Post a Comment