I know that I could use printf(%Nd, foo)
if N is constant and I know it
But the problem is that N is in variable and calculated in program
I could do it with combining sprintf
and printf
:
sprintf(formatstr, "%%%dd", N);
printf(formatstr, foo);
But is there any cleaner way?