Lower case-upper case

Please help me to write a program to convert lowercase string to uppercase string
Please!!
http://www.ascii-code.com/


a char is just a small int, so you can take advantage of this to do the conversion.

Chars can used in two ways, these are equivalent:

1
2
char MyChar = 'a'
MyChar = 97;


You can do math on them:

1
2
char MyChar = 'a'
char NewChar = MyChar + 3; //NewChar is 'd' 


Hope all goes well.
I was thinking that it is an assignment.
TIM's solution is the quick and dirty way, which won't work if the computer is from a different planet and doesn't use ASCII encoding.

If it's an assignment, do some real work to show interest.
1
2
3
4
5
6
7
switch (letter)
{
    case 'a': return 'A';
    case 'b': return 'B';
    // ...
    default: return letter;
}

@Catfish2

Your solution is very good & portable as well - the only downside is the verbosity.

As you alluded to, I am wondering how many computers there are that don't use ASCII? Mainframes, VAX machines etc. I would have thought the vast majority of computers for personal use, use ASCII, so the solution I hinted at would be fine for most people.

The code for the toupper function as described by Kernighan & Ritchie, uses math on the char value, and it also has code to deal with EBCDIC.
Topic archived. No new replies allowed.