Link to home
Start Free TrialLog in
Avatar of kensy11
kensy11Flag for Belgium

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
#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();
    }

Open in new window

Avatar of Zoppo
Zoppo
Flag of Germany image

Hi kensy11,

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
Avatar of phoffric
phoffric

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, ispunctislowerisspaceisprintisdigitisalphaisalnum
Avatar of kensy11

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>

???
You can use conio.h if it is working with getch.
You should also include ctype.h in order to use islower, etc.
Avatar of kensy11

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

 
SOLUTION
Avatar of phoffric
phoffric

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
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