tags:

views:

64

answers:

3

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

A: 

Read the Wikipedia article about C preprocessor - Macro definition and expansion (or any other document / C tutorial you can find by searching for c macro with your favorite search engine).

Felix Kling
+1  A: 

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

Kevin Toste
+1  A: 

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.

Brian Hooper