digitalmars.D - printf and %.*s
- Charlie (4/4) Apr 21 2005 This abomination needs to be destroyed, or at the very least renamed. W...
- Jarrett Billingsley (4/7) Apr 21 2005 Or, native support for printf just needs to be dropped. writef is a
- Charlie (8/19) Apr 21 2005 Posted too soon, the man pages of printf explain it. ( *nods* to german
- jicman (3/10) Apr 21 2005 Yep! Why use printf when writef is D's best way?
- Stewart Gordon (25/28) Apr 21 2005 Because printf is a C library function.
This abomination needs to be destroyed, or at the very least renamed. Why not use one of the unnamed letters instead ? Does this have some meaning that im not aware of ? Charlie
Apr 21 2005
"Charlie" <charles jwavro.com> wrote in message news:d48n49$e2m$1 digitaldaemon.com...This abomination needs to be destroyed, or at the very least renamed. Why not use one of the unnamed letters instead ? Does this have some meaning that im not aware of ?Or, native support for printf just needs to be dropped. writef is a wonderful thing..
Apr 21 2005
Or, native support for printf just needs to be dropped. writef is a wonderful thing..Yea that too. I see alot of newcomers using printf all over the place.Posted too soon, the man pages of printf explain it. ( *nods* to german ben ) Charlie "Jarrett Billingsley" <kb3ctd2 yahoo.com> wrote in message news:d48no9$ei6$1 digitaldaemon.com...Does this have some meaning that im not aware of ?"Charlie" <charles jwavro.com> wrote in message news:d48n49$e2m$1 digitaldaemon.com...WhyThis abomination needs to be destroyed, or at the very least renamed.meaningnot use one of the unnamed letters instead ? Does this have somethat im not aware of ?Or, native support for printf just needs to be dropped. writef is a wonderful thing..
Apr 21 2005
Yep! Why use printf when writef is D's best way? :-) Jarrett Billingsley says..."Charlie" <charles jwavro.com> wrote in message news:d48n49$e2m$1 digitaldaemon.com...This abomination needs to be destroyed, or at the very least renamed. Why not use one of the unnamed letters instead ? Does this have some meaning that im not aware of ?Or, native support for printf just needs to be dropped. writef is a wonderful thing..
Apr 21 2005
Charlie wrote:This abomination needs to be destroyed, or at the very least renamed. Why not use one of the unnamed letters instead ?Because printf is a C library function. There is a similar, more powerful function in D. It's called writef. http://www.digitalmars.com/d/phobos.html#stdioDoes this have some meaning that im not aware of ?The notation %.*s takes two pieces of information from the function's arguments: the length of the string and a pointer to the beginning of its data. Basically, if you have something in C like printf(("%.*s", 10, "abcdefghijklmnopqrstuvwxyz"); then it'll print the first 10 characters, i.e. "abcdefghijklmnopqrstuvwxyz". This is because in C, strings are passed as plain pointers. In D, OTOH, strings have length fields and aren't necessarily null terminated. And so when you pass a D string into printf, you are actually passing in both the length and the pointer to the beginning of the data. And so the D statement printf(("%.*s", "abcdefghijklmnopqrstuvwxyz"); is equivalent to the C statement printf(("%.*s", 26, "abcdefghijklmnopqrstuvwxyz"); If you had just "%s" instead of "%.*s", it would try to print the text pointed to by the number 26, which obviously isn't going to work. Stewart. -- My e-mail is valid but not my primary mailbox. Please keep replies on the 'group where everyone may benefit.
Apr 21 2005