Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

skipping spaces in a sprintf format

31 views
Skip to first unread message

Lynn McGuire

unread,
Oct 28, 2022, 6:33:50 PM10/28/22
to
Is there any way to skip spaces in a sprintf format ? In Fortran, one
puts 10x to skip ten spaces.

I am using the following right now:

// WRITE (OUFILE,1700) current_page
// 1700 FORMAT (67X,'PAGE:',I8)
sprintf (termin1.outbuffer, "
PAGE:%8d", prglab1.current_page);
outwri (termin1.outbuffer);

Thanks,
Lynn

Bart

unread,
Oct 28, 2022, 6:48:05 PM10/28/22
to
This prints a string within a field of 10 spaces:

printf("<%*s>\n",10,"");

"*" is used for a variable field width, padded on the left. "%-*s" will
pad on the right.


Manfred

unread,
Oct 28, 2022, 7:45:37 PM10/28/22
to
Simpler, and probably closer to what the OP needs:

sprintf (termin1.outbuffer, "%32s%8d", "PAGE:", prglab1.current_page);
outwri (termin1.outbuffer);


Bart

unread,
Oct 29, 2022, 6:08:45 AM10/29/22
to
I thought I'd missed the obvious solution..

Lynn McGuire

unread,
Oct 29, 2022, 3:02:53 PM10/29/22
to
Thank you both !

Lynn

Lynn McGuire

unread,
Oct 29, 2022, 4:55:33 PM10/29/22
to
On 10/28/2022 6:45 PM, Manfred wrote:
Or,

sprintf (termin1.outbuffer, "%66sPAGE:%8d", " ", prglab1.current_page);
outwri (termin1.outbuffer);

Thanks !

Lynn

Mike Terry

unread,
Oct 29, 2022, 5:30:03 PM10/29/22
to
I'd suggest a minor improvement: ..."%66sPage:%8d", "",...

Looking at:
printf ("==%0s==\n", " ");
printf ("==%0s==\n", "");
We get output
== ==
====

So I could say the empty string works more universally, and SAVES A BYTE OF DISK SPACE!!! :) Well,
probably you would never want to skip 0 spaces, but hey... (it can't be bad to handle edge cases,
even if you're convinced you'll never use them.)


Mike.
0 new messages