I'm trying to generate some dynamic string padding so things line up correctly, well my question is, how can I get a variable value into a printf string statement so that it is not hardcoded in. For example,
int val=10;
printf("%-5s:%s", str1, str2);
That would right-align things padding the strings by 5 via the difference from the length of str1 and 5.
he :str2
hello:str2
see :str2
Well, what if I wanted to use 'val' instead of 5. How can I have printf use the value of 'val' instead? Is this possible?
Thanks,
-bitwise
int val=10;
printf("%-5s:%s", str1, str2);
That would right-align things padding the strings by 5 via the difference from the length of str1 and 5.
he :str2
hello:str2
see :str2
Well, what if I wanted to use 'val' instead of 5. How can I have printf use the value of 'val' instead? Is this possible?
Thanks,
-bitwise