Re: Undocumented "printf()" funnies
- Posted by Chris Burch <chriscrylex at aol.com> Feb 04, 2005
- 447 views
Alan Oxley wrote: > > Hi, some observations with Eu 2.5a: > > If you leave out the "%" symbol in a printf, then its not an error, > you simply get the string within the quotes printed. Would it not be better > to either document this, or have euphoria return "Unknown printf format" > as it does if you tried printf(1,"%k",0) Where "%k" is the rubbish demo. > > Most incorrect formatting attempt within the printf quotes is not picked up > by initial parsing, only at execution time. Since you cannot use variables > within the quotes, there is no reason not to have this parsed? > > Attempting to use two decimal places is also unsupported, but it does > not give a parse error, but simply a strange result: > > }}} <eucode> > atom a > a = 100000001 > printf(1,"%3.3.3d",a) > </eucode> {{{ > will display ".3ld" (Where does the "l" come from?) > > This is also the case with eu2.4 official. > Yes, I know I can get the result I want with multiple printf's but this is > to demonstrate the problem. I also know that pretty print is not printf! > > Regards, > Alan > Hi Thats normal behaviour, and how its supposed to work, in fact its a 'cut down' version of c fprintf the % tells the parser there's a formatting character coming the 'd' 's' 'f' tell it the type (there is no 'c' in eu) the numbers inbetween tell it how to print it eg printf(1,"%d", {12}) 12 printf(1, "%03d", {12}) 012 printf(1, "%10s", {"Hello"}) Hello printf(1, "%-10s%-10s", {"Hello", "World"}) Hello World printf(1, "%-14.14s", {"Hello world its a nice day isn't it"} ) Hello world it printf(1, "%8.2f\n8.2f", {123.5678567, 45.897565432}) 123.56 45.89 etc. If a formatting character isn't found after a number its ignored, hence %3.3.3d is basically just ignored, and I've no idea where the l comes from! (Probably just garbage) if you want a % sign, then use 2 together Chris http://members.aol.com/chriscrylex/euphoria.htm http://uboard.proboards32.com/