How To Make A Program Remain Open For Windows XP

This is a discussion on How To Make A Program Remain Open For Windows XP within the C Programming forums, part of the General Programming Boards category; I use windows xp and dev c++ 4.9.9.2 compiler and my programs constantly close after scanf or printf so I ...

  1. #1
    Registered User
    Join Date
    May 2009
    Posts
    38

    How To Make A Program Remain Open For Windows XP

    I use windows xp and dev c++ 4.9.9.2 compiler and my programs constantly close after scanf or printf so I have been using getchar(); to keep the program from automatically closing.

    I know getchar(); isn't a good method because I can press letters and they will appear on the screen but if I press enter the program will then exit.
    Code:
    #include <stdio.h>
    
    main()
    {
          int a , b ,x , y , f , ;
          
          printf("Formula f = (a-b)(x-y)\n\n");
          printf("Please enter the value of a:  ");
          scanf("%d", &a);
          printf("\nPlease enter the value of b:  ");
          scanf("%d", &b);
          printf("\nPlease enter the value of x:  ");
          scanf("%d", &x);
          printf("\nPlease enter the value of y:  ");
          scanf("%d", &y);
          f = (a - b)*(x-y);
          printf("\nThe value of f is %d",f);
    
          getchar();
          getchar();
          }
    In this example I had to use getchar twice. The book I am reading uses unix and a different compilers and doesn't provide any help for my issue.

  2. #2
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    Hope is the first step on the road to disappointment.

  3. #3
    Registered User
    Join Date
    Sep 2006
    Posts
    8,868
    One link to a better compiler & IDE:

    smorgasbordet - Pelles C

    and it's free!

    Your console window stays open, by default, when you run the program in the Pelles IDE.

  4. #4
    Banned
    Join Date
    Aug 2010
    Location
    Ontario Canada
    Posts
    9,547
    Quote Originally Posted by Adak View Post
    One link to a better compiler & IDE:

    smorgasbordet - Pelles C

    and it's free!

    Your console window stays open, by default, when you run the program in the Pelles IDE.
    Hi Adak... for clarity... that is a little trick Pelle added and it works only in the IDE.

    If you want your command shell to stay open... open the command shell...then run your program.

    Hold down the WIN key and type an R then enter cmd and click OK... instant command shell.

    Go into Start -> All Programs -> Accessories ... right click on the "Command Prompt" entry and select "Pin to Task Bar" or "Pin to Start Menu"... Command shell on your task bar.

    Go into Start -> All Programs -> Accessories ... Hold the ALT key down and mouse-drag the "Command Prompt" entry out onto your desktop (or any folder) ... Command Prompt on your desktop.

    There are also all kinds of "tweaks" out there for adding an "Open command shell here" item on the right click menu of folders... very handy...
    Open Command Window Here as Administrator - Windows 7 Forums

    EDIT... Just cobbled this together for PellesC as well... http://forum.pellesc.de/index.php?topic=3542.0
    Last edited by CommonTater; 02-22-2011 at 10:32 AM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Help with a Battleship Program
    By HBlakeH in forum C Programming
    Replies: 1
    Last Post: 12-05-2010, 10:13 PM
  2. c program help :>
    By n2134 in forum C Programming
    Replies: 9
    Last Post: 02-06-2010, 11:12 AM
  3. Replies: 6
    Last Post: 07-27-2009, 03:56 PM
  4. Writing a program to make a calendar
    By Northstar in forum C Programming
    Replies: 17
    Last Post: 11-07-2007, 10:34 AM
  5. How do you make a program to interface with another?
    By Finchie_88 in forum C++ Programming
    Replies: 6
    Last Post: 08-24-2007, 03:48 AM

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