Results 1 to 5 of 5
hi everbody
when i use this code in unix/windows and linux it apear in different output:
...
char* ch="12";
printf("%05s",ch);
...
in windows and unix it.ll be "00012" but in ...
- 11-21-2008 #1Just Joined!
- Join Date
- Nov 2008
- Posts
- 1
Printf
hi everbody
when i use this code in unix/windows and linux it apear in different output:
...
char* ch="12";
printf("%05s",ch);
...
in windows and unix it.ll be "00012" but in linux " 12".
if there any solution for linux to print "00012" in output?
- 11-21-2008 #2Linux Newbie
- Join Date
- Jul 2008
- Posts
- 181
man 3 printf
- 11-21-2008 #3
That is strange. In my Unix and OS X shells, it runs like you'd expect, but in Gentoo it uses blank padding instead of zero-padding. Check the man page, but it doesn't help too much; it clearly says that the value should be zero padded when you use %0, unless you also use the '-' flag (which you aren't).
Hmm....Registered Linux User: #479567
Asking a question? Read this page first.
Now... sudo make me a sandwich.
ratiocinativeroot.blogspot.com
- 11-21-2008 #4Um, not so much. My man page says of the zero flag:Check the man page, but it doesn't help too much; it clearly says that the value should be zero padded when you use %0, unless you also use the '-' flag (which you aren't).
Code:0 The value should be zero padded. For d, i, o, u, x, X, a, A, e, E, f, F, g, and G conversions, the converted value is padded on the left with zeros rather than blanks. If the 0 and - flags both appear, the 0 flag is ignored. If a precision is given with a numeric conversion (d, i, o, u, x, and X), the 0 flag is ignored. For other conversions, the behavior is undefined.--
Bill
Old age and treachery will overcome youth and skill.
- 11-22-2008 #5
Ah! I skipped past the end after I checked that 's' wasn't in that list of conversion flags. Good call.
Registered Linux User: #479567
Asking a question? Read this page first.
Now... sudo make me a sandwich.
ratiocinativeroot.blogspot.com


Reply With Quote