how to exit using ENTER KEY/CARRIAGE RETURN ???

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • soriold
    New Member
    • Oct 2006
    • 1

    how to exit using ENTER KEY/CARRIAGE RETURN ???

    Hey there:

    I am done writing a rather large program for school and the only thing that is still driving me nuts is how to exit the program based on the fact that the return/carriage key was pressed. All input is stored as characters in an array... something like this:

    char input1[9];
    cout << "Enter number 1 (0-99999999):";
    cin >> input1;

    At this point I need to be able to determine if the user simply hits the ENTER KEY/CARRIAGE RETURN. I would appreciate any help I can possibly get because I have spent hours on this and tried ' ', '\n', and anything else I could think of....

    Thank you very much!

    Stefan
  • zahidkhan
    New Member
    • Sep 2006
    • 22

    #2
    Read each charactes instead of reading set of characters

    while(1)
    {
    int ch=0;
    cout << "Enter number 1 (0-99999999):";
    ch = getche();
    if(ch == 13 || ch == 26)//ENTER KEY/CARRIAGE RETURN
    {
    break;
    }
    }

    Comment

    Working...