By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
429,326 Members | 2,726 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 429,326 IT Pros & Developers. It's quick & easy.

Flag 'character' "space" in a format string

P: n/a
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

Apr 22 '06 #1
Share this Question
Share on Google+
2 Replies


P: n/a
On 21 Apr 2006 21:46:08 -0700, "Kannan" <ri*******@gmail.com> wrote in
comp.lang.c:
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.

--
Jack Klein
Home: http://JK-Technology.Com
FAQs for
comp.lang.c http://c-faq.com/
comp.lang.c++ http://www.parashift.com/c++-faq-lite/
alt.comp.lang.learn.c-c++
http://www.contrib.andrew.cmu.edu/~a...FAQ-acllc.html
Apr 22 '06 #2

P: n/a
Thanks Jack Klein, that helped!

-Kannan

Apr 22 '06 #3

This discussion thread is closed

Replies have been disabled for this discussion.