Flag 'character' "space" in a format string

K

Kannan

In section 7.19.6.1 on ISO C specification, it says about a format
character "space". When and how we will use this "space" format? I mean
is there a usage, for e.g. like printf("%space",...); ?

Thanks,
Kannan
 
J

Jack Klein

In section 7.19.6.1 on ISO C specification, it says about a format
character "space". When and how we will use this "space" format? I mean
is there a usage, for e.g. like printf("%space",...); ?

Thanks,
Kannan

Are you looking at an HTML or text copy of the standard? In the real
PDF version, the string "space" is shown italicized, indicating that
it is not an ordinary character but stands for the blank (' ')
character.

Try running this program:

#include <stdio.h>

int main(void)
{
int x = 457;
int y = -457;
printf("%d%d\n", x, y);
printf("% d, % d\n", x, y);
return 0;
}

No flag prints positive and negative numbers as "457" and "-457"
respectively, which could cause columns not to line up in the output.

The '+' flag prints them as "+457" and "-457" respectively, which
causes numbers with the same number of digits to output the same
number of characters, for alignment, but you may not want the leading
'+' on positive numbers.

The ' ' flag prints them as " 457" and "-457", so they contain the
same number of characters, but adding a ' ' instead of a '+' to
positive value output.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,177
Messages
2,570,954
Members
47,507
Latest member
codeguru31

Latest Threads

Top