I want to align a text with the help of a variable using the .* format specifier.
Ideally I wanted a space of 100 length with Some Text Here written and then the | sign. But this doesn't seem to work.
#include <stdio.h>
int main()
{
int prec = 100; // Assume this value to be calculated somehow and not a constant
char s[20] = "Some Text Here";
printf("%.*s", prec, s);
printf("|");
return 0;
}
Why is this so?
Thanks in Advance.
printf("%100s", s);, is that what you want?%*s, not%.*s%.*swith%*s(right aligned) or%-*s(left aligned)man 3 printffor details.