468,512 Members | 1,459 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,512 developers. It's quick & easy.

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
Oct 16 '06 #1
1 4906
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;
}
}
Oct 16 '06 #2

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

1 post views Thread by samuelberthelot | last post: by
13 posts views Thread by MZaza | last post: by
5 posts views Thread by lemlimlee | last post: by
1 post views Thread by fmendoza | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.