So I have this macro and a bunch others defined in my header file
#define COL1WIDTH 16
Which I want to use to print something like this:
word 25 Dir1/FileB 129 Sat Jan 1 00:00:02 2011 12 1(x4), 2(x2), 3(x2), 4(x2), 5(x2)
How does the syntax to get the macro work? Tried a bunch and it keeps screwing up.
Tried this
printf("%COL1WIDTHs\t",index->terms[0].term);
printf("%" #COL1WIDTH "s\t", ...
Read up on token pasting and stringizing in the C pre-processor.
Macros aren't expanded inside strings. Here there's a decent workaround — write
printf("%*s\t", COL1WIDTH, index -> terms[0].term);
and COL1WIDTH will be used in place of the *.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With