Skip to main content
gamedev.net
🔒 Locked

Quick help please

Started by The Alchemist Sep 4, 2000 at 2:33 AM 3 replies 450+ views
Original Post
The Alchemist
The Alchemist
does anyone know a function that works like getch() but for int not char? ========= Nothing is perfect. I´m nothing. So i´m perfect.
"Everything works out in the end, if it doesn't then it is not the end"
Ironblayde
Ironblayde
What do you mean, exactly? Do you want to detect a single keypress and get its ASCII code?

int num = (int)getch();

Or do you want to detect a keypress that is going to be one of the number keys?

int num = (int)getch() - 48;

Or do you mean you want to have the user enter an integer and then press Enter when they''re finished?

int num;
scanf("%d", #);

Wow, I haven''t used scanf() in a long time.

-Ironblayde
 Aeon Software
"Your superior intellect is no match for our puny weapons!"
The Alchemist
The Alchemist
whoa!!! this one was realy quick

of curse i wanna the one of the middle

quote:

Or do you want to detect a keypress that is going to be one of the number keys?

int num = (int)getch() - 48;



this "-48" stuff realy works?? if so i can use it



=========
Nothing is perfect.
I´m nothing.
So i´m perfect.
"Everything works out in the end, if it doesn't then it is not the end"
Ironblayde
Ironblayde
Yep, it should work for you. The "(int)getch()" part gets a character out of the keyboard buffer and converts it to an integer - the ASCII code of the character. The "-48" is there because the ASCII code for the ''0'' key is 48, so when you press keys ''0'' through ''9'', the numeric value will be stored in "num".

-Ironblayde
 Aeon Software
"Your superior intellect is no match for our puny weapons!"
The Alchemist
The Alchemist
thanks! i gonna try it

=========
Nothing is perfect.
I´m nothing.
So i´m perfect.
"Everything works out in the end, if it doesn't then it is not the end"

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.