开发者

convert to uppercase using macros

开发者 https://www.devze.com 2023-01-05 22:40 出处:网络
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 #defi

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

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号