convert to uppercase using macros
I have been given a task to covert lower case character into upper case by using macros .the problem is that 开发者_高级运维i have never been introduced to macros. i just know that its something #define name size .. please can anyone guide me on this issue
The answer above would also change things that aren't letters. Perhaps...
#define LOWERTOUPPER(x) (('a' <= (x) && (x) <= 'z') ? ((x - 'a') + 'A') : (x))
although that would give trouble if it were invoked as
LOWERTOUPPER(*p++);
and also wouldn't be right for the EBCDIC character set. All of which goes to prove that this sort of thing is a Bad Idea.
The simplest way to do this would be something like this:
#define LOWERTOUPPER(x) ((x - 'a') + 'A')
Then, you would use this function like follows:
character = LOWERTOUPPER('z');
Which would result in the character variable holding a 'Z'.
精彩评论