Thread: why .exe file is not working in windows of c program

  1. #1
    Registered User
    Join Date
    Jan 2011
    Posts
    113

    Question why .exe file is not working in windows of c program

    OS : Windows XP
    Software of C programming : Turbo C/C++ IDE

    Actually we know that when we write program, compile and run it ..
    Object & Executable files are created, I read in a book that the .exe file of the program can be carried anywhere ( I mean from any windows computer to another) and use it for running the program.
    But what I found is that the .exe file is not even opening in my computer itself.

    The .exe file could only take inputs from me but couldn't give output, its just closing..
    For some programs which don't have any functions which take input, The .exe file is not even opening completely ( It's just opening and closing immediately)..

    why this is happening ??
    If this happens all the time for all, what's the whole point of writing programs.. ??

  2. #2
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,336
    Because that's the way you wrote it.

    Command-line programs are designed to be run from the command line; consequently trying to run them by double-clicking is already an error. Open a command prompt and run your program there.

    (If you intend to write programs that are to be run by double-clicking, then you need to adjust your program to deal with the different style of user interaction. For instance, your program should not just end (i.e. with "return 0") when calculations are finished, since that will close the program -- it should only end based on the user sending it a message to close.)

  3. #3
    Registered User krishnapollu's Avatar
    Join Date
    Dec 2010
    Location
    KERALA
    Posts
    29
    it may depend on your program..

    jus post what u hav written.

  4. #4
    Registered User
    Join Date
    Jan 2011
    Posts
    113

    Question my sample program ;

    As I'm just started learning C programming..
    I'm posting simple program..

    Code:
    /* even if we go for returning a value instead of using void.. say return 0 */
    #include <stdio.h>
    void main()
    {
    int a,b,r;
    printf("\nenter two numbers a,b to find the sum \n");
    scanf("%d %d",&a,&b);
    r=a+b;
    printf("%d",&r);
    }
    Do edit if it has some minor errors (sometimes happen while writing )..
    what i found is when i open the .exe file of this program, it is taking the input but immediately closing after that..
    why ??
    As I'm a beginner please explain me in detail and clearly why it happens and how do i write code to make sure that it works the way I said

  5. #5
    Registered User
    Join Date
    Sep 2004
    Location
    California
    Posts
    3,268
    bit∙hub [bit-huhb] n. A source and destination for information.

  6. #6
    Registered User
    Join Date
    Nov 2010
    Location
    Long Beach, CA
    Posts
    5,909
    When you double click on a command line program to run it, Windows opens a command prompt, runs your program, then exits the command prompt when your program is finished. It doesn't leave it waiting for you to type more commands, as it would if you opened a command prompt on your own and typed the name of your program to run. The solution is to:
    1. Run it from the command prompt by typing the name of your program
    2. Put something like system("PAUSE"); to make it wait for you to press some key to exit.

  7. #7
    Registered User
    Join Date
    Dec 2007
    Posts
    2,675
    Software of C programming : Turbo C/C++ IDE
    Serious error detected; use of outdated software is detrimental to one's programming health.

    EDIT: Regardless of what Adak says...

  8. #8
    Registered User
    Join Date
    Sep 2008
    Location
    Toronto, Canada
    Posts
    1,834
    Code:
    printf("%d",&r);
    should be
    Code:
    printf("%d",r);
    To make the progam pause for you to read its results I put the following:
    Code:
    printf("Press any key to exit.\n");
    _getch();
    exit(0);

  9. #9
    Registered User
    Join Date
    Sep 2008
    Location
    Toronto, Canada
    Posts
    1,834
    Quote Originally Posted by tabstop View Post
    Command-line programs are designed to be run from the command line; consequently trying to run them by double-clicking is already an error. Open a command prompt and run your program there.
    I disagree. I routinely write programs which can be run either by first opening a command prompt, or by double clicking a .bat file which runs the .exe. The program merely has to pause long enough to let someone read its output if any. Or you can pipe the output to a text file.

  10. #10
    Registered User \007's Avatar
    Join Date
    Dec 2010
    Posts
    179
    You need to put

    system("PAUSE");

    Before

    return 0;

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. A development process
    By Noir in forum C Programming
    Replies: 37
    Last Post: 07-10-2011, 10:39 PM
  2. Replies: 2
    Last Post: 09-16-2009, 06:00 AM
  3. help with text input
    By Alphawaves in forum C Programming
    Replies: 8
    Last Post: 04-08-2007, 04:54 PM
  4. Script errors - bool unrecognized and struct issues
    By ulillillia in forum Windows Programming
    Replies: 10
    Last Post: 12-18-2006, 04:44 AM
  5. Last program!!
    By buckwheat88 in forum C++ Programming
    Replies: 12
    Last Post: 01-17-2006, 12:31 PM

Tags for this Thread