M
MikeC
Folks,
Can the width specifier be used in a printf() text string?
If I execute...
printf("%4s", ".........."); it prints ten dots.
If I execute
printf("%4s", "."); it prints one dot.
I was hoping to use sprintf to fill in a number of spaces in a field, such
as...
int spaces = 6;
sprintf(buf, "head %*s tail", spaces, " ");
If printf() can't do it, I know I can write a function that will handle it,
but is there a more elegant way? printf() would be attractive because I
would be able to fill in "head", "tail" and a given number of spaces between
them, all in one statement.
Thanks,
MikeC
--
Mental decryption required to bamboozle spam robots:
mike_best$ntlworld*com
$ = @
* = dot
Can the width specifier be used in a printf() text string?
If I execute...
printf("%4s", ".........."); it prints ten dots.
If I execute
printf("%4s", "."); it prints one dot.
I was hoping to use sprintf to fill in a number of spaces in a field, such
as...
int spaces = 6;
sprintf(buf, "head %*s tail", spaces, " ");
If printf() can't do it, I know I can write a function that will handle it,
but is there a more elegant way? printf() would be attractive because I
would be able to fill in "head", "tail" and a given number of spaces between
them, all in one statement.
Thanks,
MikeC
--
Mental decryption required to bamboozle spam robots:
mike_best$ntlworld*com
$ = @
* = dot