Thread: prompt for pressing "enter"

  1. #1
    Registered User
    Join Date
    Nov 2001
    Posts
    7

    prompt for pressing "enter"

    I need to stop the output till one presses the <ENTER> key.
    well , with BASIC I used to do this:
    DO WHILE INKEY$ = ""
    LOOP
    with c++ , under DOS one could use
    #include <stdlib.h>
    #include <stdio.h>
    int main()
    {
    system ("pause");
    return 0;
    }
    but since I switched to Linux (and Kdevelop) all the old stuff is of no use.

    another question: when I put a prompt with the cin >> something ; function how can I trap errors (eg a charachter instead of an int) ?

    10x
    Stefano Jodice
    [email protected]

  2. #2
    Registered User WebSnozz's Avatar
    Join Date
    Oct 2001
    Posts
    102
    You could take everything as an array of characters and then on each check each character

    bool CheckForInt(char[10])
    {
    for(int i=10; i<10; i++)
    {
    if ((int(char[i])<58)&&(int(char[i])>47)){return TRUE;}

    return FALSE;
    }
    }


    assuming you aren't going above ten digits

    numeric chars are between the values 48-57

    I guess you'd probably call that function in a do while condition the encloses the input promting so that it continually prompts until the user puts in a integer value

    Somehow you'd have to convert it back to a number though.

    There's probably a better way to do it.
    WebSnozz-
    Cats have no butt cheeks.
    If one farted, then it would make a flute noise.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. How to hide command prompt using C language?
    By deob in forum C Programming
    Replies: 6
    Last Post: 03-24-2009, 08:17 PM
  2. Control characters to emulate a prompt?
    By xconspirisist in forum Windows Programming
    Replies: 3
    Last Post: 02-08-2006, 04:16 PM
  3. Male Perfectionist seeks Perfect Prompt
    By sean in forum Tech Board
    Replies: 10
    Last Post: 07-17-2004, 03:29 PM
  4. Removing spaces from a "string"
    By sytaylor in forum C++ Programming
    Replies: 20
    Last Post: 03-25-2004, 10:14 AM
  5. Password prompt in unix w/o \b
    By rafe in forum C++ Programming
    Replies: 1
    Last Post: 10-09-2002, 08:54 AM