Hey Guys,
I'm learning about marcros. Specifically #define with parameters. I cannot seem to get my loop to work using the code provided by the book. The Goal: print ABCD from abcd but, I'm supposed to use this code:
Code:
putchar(TOUPPER(s[++i]));
.
Here's the complete program:
Code:
//ANSWER: http://knking.com/books/c2/answers/c14.html
// Problem 5
#include <stdio.h>
#include <string.h>
#define TOUPPER(c) ('a'<=(c)&&(c)<='z'?(c)-'a'+'A':(c))
int main(){
char s[6];
strcpy(s, "abcd");
int len=strlen(s), i;
for(i=0;i<len;){ // DOESN'T WORK, PRINTS " D"
printf(" ");
putchar(TOUPPER(s[++i]));
}
/*for(i=0;i<len;i++){ // THIS CODE WORKS
printf("%c, ",TOUPPER(s[i]));
}*/
return 0;
}
Somehow the looping syntax is flawed. Please help.