Tuesday, September 13, 2011

How do I run a C program? I tried everything I know?

Hello, I am getting back into programming and I am having trouble running my C program. Ok here's what I've done so far:



downloaded Dev-C++ compiler



made a file called (helloworld.c)



clicked on compile and run in the compiler



it created the helloworld.o file and the helloworld.exe file



now when I double clicked the .exe file from my directory it did nothing, I even tried to execute from the command prompt by changing the directory to the one I created for my new program and typed (start helloworld.exe), it did absolutely nothing.]\



Im stuck, can anybody help?How do I run a C program? I tried everything I know?
The program is running and the window is closing before you can see it. Put something at the end of your program to make the program pause befor exiting, e.g. wait for the user to hit return:



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



int main(void)

{

....printf(';Hello world!\n';);

....printf(';Hit return to continue...!\n';);

....getch();

....return 0;

}How do I run a C program? I tried everything I know?
How about ';Build and Run';?
OK so here we go:



So I'm assuming from your question that the program compiled ok and that it created an executable file (.exe). Right?



So I have one solution:

You went to the programs directory and double clicked it. Did the Console (the black screen) come in a then just dissapear.



If that is happening this is what is happening:

Your program is executing so fast you have no time to see it



Here's what you do:

Add this statement to the end of your code, before the return 0:

system(';pause';);



This causes your program to wait for user input (pressing a key) before terminating.



Hope this helps!



~Patrick, currently developing PDOS32 Operating System %26amp; Dynatec Researcher Beta

No comments:

Post a Comment