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
Asked
Active
Viewed 1.0k times
0
-
3Read a book on C - there is a list at http://stackoverflow.com/questions/562303/the-definitive-c-book-guide-and-list – Jul 05 '10 at 10:21
-
3If the homework is on macros, but you have never been "introduced" to macros, what were you doing in class? Read your course material/lecture notes or wakeup. Thinking that it is `#define
` is not going to get you far in this assignment; what you 'know' is wrong. Also your tutor should probably refrain from giving you homework that simply encourages bad programming technique.
2 Answers
7
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
- 21,544
- 24
- 88
- 139
5
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'.

Toast
- 356
- 1
- 2
- 8