# Thread: C program open only .exe file

1. ## C program open only .exe file

Hello, I have a general question about the C programming language. I have programmed the below program in Codeblocks. I have now closed Codeblocks and I would like to run only the .exe file. So I go to the corresponding folder \bin\Debug and there is the .exe file. As soon as I execute the file, the command prompt opens very briefly but nothing else happens. When I run the .c file into code blocks and run it, the program executes properly. My question: Why does the created .exe file not work? Because if I am right the automatically created .exe file should behave in the same as the program executed directly in codeblocks.

Why the .exe file does not open, mayby my settings are not ok. Attached is also a video.

Code:
#include <stdio.h>
#include <stdlib.h>

int main()
{
int x;

for(x=0;x<10;x=x+1,printf("%d\n",x))
;
return 0;
}

2. I guess you run the .exe from Windows shell. It's a common problem in Windows.
If you run it in Code::Blocks, the IDE keeps the console window open for you.

To solve the problem you can run your app from the console or add getchr(); before the return statement.

3. Originally Posted by thmm
I guess you run the .exe from Windows shell. It's a common problem in Windows.
If you run it in Code::Blocks, the IDE keeps the console window open for you.

To solve the problem you can run your app from the console or add getchr(); before the return statement.
Did you mean getchar(), getch(), or getche(), instead of "getchr()"?

I would always use getchar() instead of getch() or getche().

In any case, you should avoid any conio.h functions, or any other Mickey\$oft extensions.

4. Well the way to run a console program is by opening a console (cmd.exe) and then doing
cd \path\to\bin\Debug
prog.exe

Double-clicking on it in explorer will just create a console for the duration.

5. Originally Posted by rstanley
Did you mean getchar(), getch(), or getche(), instead of "getchr()"?
I meant getchar(), was just a typo.

6. Ok, thanks for the help