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

asked on

convert lower case to upper case

Hallo,

i am working on a program , it ask for a character and it gives an error if its a number

Now the next thing i want to do is if we give a character in lower case i want the program to convert it to upper case is it possible doing it, only using the #include <conio.h> ??

Thanks
#include <stdio.h>
#include <conio.h>
int main (void)

{
    int key;
    
    printf ( "give a key ");
    key = getch ();
     
     if (key >= '0' && key <= '9')
       printf ("\n\nError the key was not a character\n\n hit enter to close the program");
    
           if (key >= 'a' && key <= 'z')
              printf ("\n\nthe key was %c ",key);
    
    getchar();
    
    
    }

Open in new window

Avatar of evilrix
evilrix
Flag of United Kingdom of Great Britain and Northern Ireland image

You can use toupper to do this.
http://www.cplusplus.com/reference/clibrary/cctype/toupper/

You will need to enumerate through the string and uppercase each char.
Avatar of neuroskunk
neuroskunk

string EventName;

EventName = txtEventName.Text;

EventName.ToUpper();

txtEventName.Text = EventName;
ASKER CERTIFIED SOLUTION
Avatar of Zoppo
Zoppo
Flag of Germany image

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

ASKER

thanks
yes, it should be possible,
use               printf ("\n\nupper case of the the key was %c ",key-32);
and this will give you the upper case.
ah, Zoppo has already given the answer. ! :)
The problem with doing it that way is it relies on the underlying character encoding being of a format where this will work and there is nothing to say this is the case. The toupper function is a standard C function that is guaranteed to correctly convert to upper case given the correct locale (if you use the C++ version).