Thread: End of Program

  1. #1
    Registered User
    Join Date
    Aug 2003
    Posts
    19

    End of Program

    This is a total noob question but when I run a simple program how do I keep my program window open until I enter a character from the keyboard. Like I said, I'm new at this and thought I might come here for help. Thanks in advance.

  2. #2
    Registered User
    Join Date
    Aug 2003
    Posts
    19
    Nevermind. I'm kind of slow at this, but I figured it out. Thanks.

  3. #3
    Registered User
    Join Date
    Aug 2003
    Posts
    127
    for example
    Code:
    #include<stdio.h>
    #include<conio.h>
    
    int main()
    {
       printf("input a char to exit the program\n");
       getch();
       return 0;
    }
    Nana C++ Library is a GUI framework that designed to be C++ style, cross-platform and easy-to-use.

  4. #4
    Registered User
    Join Date
    Aug 2003
    Posts
    19
    Thanks for the response.

    Well I thought I fixed it.

    I've tried the

    Code:
    #include <stdio.h>
    main()
    {
        char d1, d2, d3, d4;
        int x;
        scanf("%d%c%c%c%c", &x, &d1, &d2, &d3, &d4);
        printf("%d%c%c%c%c", x, d1, d3, d2, d4);
        getchar();
        return 0;
        
    }
    but it doesn't keep the DOS window open so that I can view the input numbers.

  5. #5
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,897
    scanf left a newline in the stream and getchar read it. Throw in another getchar to eat the newline and you'll be set.
    My best code is written with the delete key.

  6. #6
    Registered User
    Join Date
    Aug 2003
    Posts
    19
    Thanks. Who woulda thunk to put in 2 getchar()s. Maybe everyone else but me.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. help! Placement of nodes in a Linked List
    By lostmyshadow in forum C Programming
    Replies: 6
    Last Post: 12-17-2007, 01:21 PM
  2. Using variables in system()
    By Afro in forum C Programming
    Replies: 8
    Last Post: 07-03-2007, 12:27 PM
  3. singly linked to doubly linked
    By jsbeckton in forum C Programming
    Replies: 10
    Last Post: 11-06-2005, 07:47 PM
  4. Cant figure out how to end my program
    By Summonerur in forum C Programming
    Replies: 9
    Last Post: 10-11-2004, 10:53 PM
  5. My program, anyhelp
    By @licomb in forum C Programming
    Replies: 14
    Last Post: 08-14-2001, 10:04 PM