0

// If I have an int, eg

int num=3;

//then how can I do this

printf(" %nums", some_string);

// to get it right aligned by 3 characters

context: I need to use a loop to print statements with variable alignments depending on the order they are printed, if I cant use a variable I cant do that.

1 Answers1

0

Yes, it's in the printf manpage:

Instead of a decimal digit string one may write "*" or "*m$" (for some decimal integer m) to specify that the field width is given in the next argument, or in the m-th argument, respectively, which must be of type int.

aragaer
  • 17,238
  • 6
  • 47
  • 49