C pre-processor and ANSI standard

laman at sdcsvax.UUCP laman at sdcsvax.UUCP
Mon Sep 10 23:57:39 AEST 1984

If you want a macro to write "n" spaces try:

#define		spaces(n)	printf("%*s", n, "")

This of course will only work on systems that understand a '*' flag in
printf().  The '*' flag goes back to V7, if memory serves me right.

		Mike Laman, NCR @ Torrey Pines
		UUCP: {ucbvax,philabs,sdcsla}!sdcsvax!laman

P.S.  What about a negative "n" you say.  Try:

#define		spaces(n)	printf("%*s", (n <= 0) ? 0 : n, "")

If you want to worry about if-then-elses then go ahead and pull the check
out of the arguments so you can side step the printf.

More information about the Comp.lang.c mailing list