how to make a exe file which can run directly

This is a discussion on how to make a exe file which can run directly within the C Programming forums, part of the General Programming Boards category; I am using Microsoft Visual C++ to write a C program. But when compile it, it create a exe file. ...

  1. #1
    Registered User
    Join Date
    Jul 2010
    Posts
    3

    how to make a exe file which can run directly

    I am using Microsoft Visual C++ to write a C program. But when compile it, it create a exe file. When I double click on it, it open and close immediately. Yes, it run fine in the cmd window.

    The question is, how can I make an exe file which can run when I double click on it. ( what I was trying to say is, when I download an exe from the internet, I often double click on it and it run, no install require). I want to create an exe like that.

    Could you please guide me on how to do it?

    Thank you very much

  2. #2
    Registered User
    Join Date
    Jul 2010
    Posts
    33
    You could add the following to the end of your program's main function ( but before the return satement:

    Code:
    int main()
    {
        //...other code...
        getchar();
        return 0;
    }
    This makes the program wait for input at the command line, to end your program you could just type in a character and press the enter button on your keyboard.

    Also, Visual C++ has an option to run it as well that doesn't require the getchar(); line. If you navigate to Debug -> Start Without Debugging that should run your program without closing immediately.

  3. #3
    Registered User
    Join Date
    Jul 2010
    Posts
    3
    I understood what you meant. But I guess I didn't make my point clear enough.

    My point is to make an exe program which is no longer a DOS or cmd program. I want to make a window program.

    Right now, I just want to make a very simple window environment exe program. Such as enter an input and print that input out.

    I know how to write the code, but I don't know how to make a window environment exe.

    Could you please help me to do so?

    Thanks

  4. #4
    Registered User claudiu's Avatar
    Join Date
    Feb 2010
    Location
    London, United Kingdom
    Posts
    2,094
    So, you want to use a GUI(Graphical User Interface). For that, you need to start reading some tutorials on GUI programming, which will differ depending on your OS platform. If you are using Windows, it's the win32 library, in Linux the X window system or others(depending on the flavor).
    1. Get rid of gets(). Never ever ever use it again. Replace it with fgets() and use that instead.
    2. Get rid of void main and replace it with int main(void) and return 0 at the end of the function.
    3. Get rid of conio.h and other antiquated DOS crap headers.
    4. Don't cast the return value of malloc, even if you always always always make sure that stdlib.h is included.

  5. #5
    Registered User
    Join Date
    Jul 2010
    Posts
    3
    Thank you very much. I'll look into it

  6. #6
    Third Eye Babkockdood's Avatar
    Join Date
    Apr 2010
    Posts
    352
    When I make Windows equivalents of my programs, I always append the following.

    Code:
    #include <conio.h>
    
    main() {
         /* code code code... */
         getch();
    }
    This will leave the CMD window open until the user presses a key.

  7. #7
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Posts
    23,027
    getch is non-standard and main must return int.
    You may as well use getchar. But this is only necessary for console programs.
    And there are other ways: SourceForge.net: Pause console - cpwiki
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Formatting a text file...
    By dagorsul in forum C Programming
    Replies: 12
    Last Post: 05-02-2008, 04:53 AM
  2. Need Help Fixing My C Program. Deals with File I/O
    By Matus in forum C Programming
    Replies: 7
    Last Post: 04-29-2008, 08:51 PM
  3. Inventory records
    By jsbeckton in forum C Programming
    Replies: 23
    Last Post: 06-28-2007, 05:14 AM
  4. help with text input
    By Alphawaves in forum C Programming
    Replies: 8
    Last Post: 04-08-2007, 05:54 PM
  5. Batch file programming
    By year2038bug in forum Tech Board
    Replies: 10
    Last Post: 09-05-2005, 04:30 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21