Re: sprintf(): different output on Windows and Linux
- Posted by Julio C. Galaret Viera <galaret at adinet.com.uy> Apr 06, 2006
- 754 views
Chris Burch wrote: > > Julio C. Galaret Viera wrote: > > > > sprintf("%03s", {"62"}) > > > > on Windows: "062" > > on Linux: " 62" (a blank space instead of zero) > > > > Why? It's supposed to produce the same output on both, isn't it? > > Yes it is. The windows one is wrong (AFAIK) > > if you want a printed field of 3, and only 3 characters, you should use %3.3s. > if you want it justified to the left you should use %-3.3s. > > The leading zero is generally only used with digits, so with strings the > number > 03 should be interpreted as 3, whereas with a number it should be interpreted > as 'fill up empty spaces with zeros' - I think! > > Chris > > > <a > href="http://members.aol.com/chriscrylex/euphoria.htm">http://members.aol.com/chriscrylex/euphoria.htm</a> > <a href="http://uboard.proboards32.com/">http://uboard.proboards32.com/</a> > <a > href="http://members.aol.com/chriscrylex/EUSQLite/eusql.html">http://members.aol.com/chriscrylex/EUSQLite/eusql.html</a> As you say, «generally» used with numbers, but in this case I have sequences with characters from 0 to 9. So I didn't know what the behaviour of the sprint() function would be if I mixed a format string designed to be used with numbers and a sequence. The reason I did that way (that is, not using the correct format string for sequences you mention) is that being files, I don't want leading blank spaces at the begining of their names. After realizing (on Windows) that the output was the same as expected with numbers, I decided to use it without converting the strings to numbers. To my surprise when I ported the program to Linux, file names were created the other way. The OS wisely puts a "\" at the begining of the name, but the "\" sign in front of a file name puts me a litle nervous. I also think the function behaviour on Linux is what one may expect according to the normal use of sprintf()... but Windows doesn't think so! JG