for loop in #define

Posted by hspim on Stack Overflow See other posts from Stack Overflow or by hspim
Published on 2010-04-01T06:58:51Z Indexed on 2010/04/01 7:03 UTC
Read the original article Hit count: 300

Filed under:
|
|
#include <stdio.h>
#define UNITS {'*', '#', '%', '!', '+', '$', '=', '-'}

#define PrintDigit(c, d) (for (i=0; i < c ; i++)putchar(unit[d]);)

char unit[] = UNITS;

//void PrintDigit(c, element) {
//  int i;
//  for (i=0; i < c ; i++)
//      putchar(unit[element]);
//}


int main( ) {
    int i, element=4;
    PrintDigit(10, element);
    putchar('\n');
    return 0;
}

I have the function here PrintDigit() which works as expected. When attempting to turn the function into a #define however gcc keeps throwing a syntax error on the for loop. Any idea what the problem is?

© Stack Overflow or respective owner

Related posts about c

    Related posts about define