convert lower case to upper case

kensy11 used Ask the Experts™

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> ??

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

Open in new window

Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
evilrixSenior Software Engineer (Avast)

You can use toupper to do this.

You will need to enumerate through the string and uppercase each char.
string EventName;

EventName = txtEventName.Text;


txtEventName.Text = EventName;
Hi kensy11,

since I guess you again want a solution without use of 'isupper' or 'toupper' (@evilrix FYI: you could do it like this:

> if ( key >= 'a' && key <= 'z' )
>  key = key - 'a' + 'A';

Hope that helps,

CompTIA Cloud+

The CompTIA Cloud+ Basic training course will teach you about cloud concepts and models, data storage, networking, and network infrastructure.


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. ! :)
evilrixSenior Software Engineer (Avast)

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).

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial