Which way is better, http://ideone.com/w44WC or http://ideone.com/8EJEC ? Do I use three consecutive for-loops, or should I use a single for-loop to do the same thing, or should I do something else?
They're both fine. You can probably get clever with a single nested for and some solid use of the mod (%) operator.
You repeated a lot of code there. Remove the repetition like this: #define PUTCHARS(ch,times) while (times-- > 0) putchar(ch) Then you can just call PUTCHARS('x', 80);
I should note though, you're not 'calling' anything. Just creating a macro for replacement
Is it better to define macros to do some procedure, or to define functions instead?
Tough question. Sometimes the compiler will inline procedures for you, which makes for the same thing as defining a macro. But not always. It's an efficiency tradeoff, as these things often are in C/C++.
Join our real-time social learning platform and learn together with your friends!