Thread: C program open only .exe file

  1. #1
    Registered User
    Join Date
    Feb 2021
    Posts
    3

    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.

    Download | file.io

    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. #2
    Registered User
    Join Date
    Sep 2020
    Posts
    150
    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. #3
    Registered User rstanley's Avatar
    Join Date
    Jun 2014
    Location
    New York, NY
    Posts
    1,128
    Quote Originally Posted by thmm View Post
    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. #4
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,675
    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.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  5. #5
    Registered User
    Join Date
    Sep 2020
    Posts
    150
    Quote Originally Posted by rstanley View Post
    Did you mean getchar(), getch(), or getche(), instead of "getchr()"?
    I meant getchar(), was just a typo.

  6. #6
    Registered User
    Join Date
    Feb 2021
    Posts
    3
    Ok, thanks for the help

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. How can i open a .exe file from my c++ program?
    By Roleaxes in forum C++ Programming
    Replies: 6
    Last Post: 04-16-2013, 12:27 AM
  2. Replies: 1
    Last Post: 06-20-2011, 12:36 PM
  3. how do you open notepad file in a c program?
    By thisbeme in forum C Programming
    Replies: 3
    Last Post: 04-03-2011, 07:10 AM
  4. How to open file from program's dir
    By Abda92 in forum C Programming
    Replies: 6
    Last Post: 07-29-2007, 10:23 PM
  5. change this program to open a file
    By A F Army in forum C Programming
    Replies: 3
    Last Post: 04-05-2003, 05:25 PM

Tags for this Thread