kensy11
asked on
Keyboard Input
Hallo,
i want to make a program than show what key has been pressed , is it a lower / upper case character ? is it a number ? punctuation mark ?
i have made de code i looks like this now it shows whar key is been pressd down but it dont say for example it is upper case character , or for example its a number How can i do it does it use the if statement ?
Thank you
i want to make a program than show what key has been pressed , is it a lower / upper case character ? is it a number ? punctuation mark ?
i have made de code i looks like this now it shows whar key is been pressd down but it dont say for example it is upper case character , or for example its a number How can i do it does it use the if statement ?
Thank you
#include <stdio.h>
#include <conio.h>
int main (void)
{
int key;
printf ("press any key on your keyboard");
key = getch();
printf ("\nthe key was %c",key);
getchar();
}
Take a look at isupper() http://www.cplusplus.com/reference/clibrary/cctype/isupper/Notice the list on the left bottom part of this page. It has other functions that you may find useful. For example, ispunctislowerisspaceispri ntisdigiti salphaisal num
ASKER
so there is no way i could use
#include <stdio.h>
#include <conio.h> for checking that ?
i shuld use
#include <stdio.h>
#include <ctype.h>
???
#include <stdio.h>
#include <conio.h> for checking that ?
i shuld use
#include <stdio.h>
#include <ctype.h>
???
You can use conio.h if it is working with getch.
You should also include ctype.h in order to use islower, etc.
You should also include ctype.h in order to use islower, etc.
ASKER
i only want to use conio.h and one other quastion , can i do the same thing with getch ?
i mean now when i press a key it shows what key it was but idoesn't say for example if it was a upper case character
i mean now when i press a key it shows what key it was but idoesn't say for example if it was a upper case character
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Note that isupper returns a true (i.e., any value other than 0) if and only if two conditions are met:1) key is an alphabetic letter2) and this alphabetic letter is uppercase
you can use functions like 'isupper', 'isdigit', 'ispunct' and some more to get those infos about a 'char' here you can find some more: http://man.cx/isdigit%283C%29
Hope that helps,
ZOPPO