Talk:Printf

message: The edits by User:68.100.130.21 on this page were by me. --Graue 21:31, 11 October 2005 (UTC)
thread_title:  Unattributed edits 

message: the v-variants need to be explained better. Why are they necessary? I can understand that this has to do with the fact that you cannot simply
 char* f(char* s, ...){
     printf(s, ...); // what should the arguments be???
 }
but a code example for how vprintf solves that would be nice. --MarSch 13:33, 13 April 2006 (UTC)
thread_title:  v variants 

message: I think it would be very helpful to have an implimentation of printf - how it works at a lower level. I would think that it uses write() at the most basic portable level, but I have no idea where to find if thats true, or how it works. Fresheneesz 22:07, 17 September 2006 (UTC)
thread_title:  Implimentation of printf 

message: Could some one translate russian article? —The preceding unsigned comment was added by 89.223.67.131 (talk) 14:00, 14 January 2007 (UTC)
thread_title:  [[:ru:printf]] 

message: The current explanation is confusing although strictly speaking correct. The statement that the value n is the next argument means that n should be the next argument that printf will parse from its argument list. Because printf at the point when it reads the '*' has not read the data value yet; this means that the width argument should come before the associated data value. Thus, the example is correct. I can't figure out how to re-word this so that it will be clear immediately clear even if the reader doesn't understand how printf works internally. --24.226.31.7 05:08, 8 February 2007 (UTC)
replies: text: I've rewritten the explanations of "*". See if it works any better. --Deryck C. 02:53, 10 February 2007 (UTC)
thread_title:  '*' width identifier (pad to width given in argument) 

message: echo -n -e "$FOO\t$BAR'
Are the quotations right? I don't think so, but I do not know whether " or ' is correct in Shebang (Unix)? --Lazer erazer 19:31, 10 April 2007 (UTC)
replies: text: They weren't right; and they should've been " in order to have the $ character assume the appropriate semantics (using ' would've protected the $ from shell interpretation).  I fixed. --tiny plastic Grey Knight ⊖ 13:18, 2 August 2007 (UTC)
thread_title:  Typo 

message: How about some history here?  I failed to learn the thing I wanted to learn when I came to read this article:  Where did the name "printf" come from?  What's the 'f' for?  Why isn't it simply named "print"?  I remember being originally told that the 'f' stood for 'function', because it was the print function, but that makes little sense since *every* library call in C is a function.  It wasn't fopenf() or strcpyf() or mallocf().  So what's the origin of the 'f'?
: As far as I'm aware it means "print formatted text".  I don't have a source for that, though. --tiny plastic Grey Knight ⊖ 11:40, 2 August 2007 (UTC)
thread_title:  history 

message: Lua has a %q specifier in its string.format() function (which is basically just like PHP's sprintf()) which accepts a string argument and prints it with all special characters (like quotes, for instance) escaped with backslashes (no quote delimiters are placed on the result unless you include them in the format string yourself).  Does this variant exist in any other languages?  Is it worth mentioning? --tiny plastic Grey Knight ⊖ 11:40, 2 August 2007 (UTC)
replies: text: Bash's printf builtin supports it. —82.36.30.173 (talk) 00:47, 10 August 2012 (UTC)
thread_title:  %q 

message: I made a new, smaller, tidier lead paragraph, and moved the old one down into a "printf in different languages" section.  That bit reads a bit oddly now that it's a section, but then again a lot of the article wouldn't suffer from a rewrite.  I think a slightly more language-agnostic approach would be nice, with any particularly notable language idiosyncracies collected into a section lower down. --tiny plastic Grey Knight ⊖ 13:11, 2 August 2007 (UTC)
thread_title:  rewrites 

message: The reason that I said that Java's implementation of printf gives it the functionality of both printf and fprintf it that it is possible to open a PrintStream object to write to a file and call that object's printf method to write to that file (similar in practice to fprintf, but more syntactically similar to printf). Because System.err and (obviously) System.out are both PrintStream objects, they both support printf. --Btx40 (talk) 21:07, 28 April 2008 (UTC)
replies: text: It has aleady been mentioned. I'm not sure if the Java implementation is the only one to throw exception on an error condition. (There is the .NET impementation, but that uses a substantially different syntax) --Btx40 (talk) 18:58, 21 May 2008 (UTC)
replies: text: Actually, I added the mention of it shortly after posting in this.  --64.175.43.196 (talk) 22:29, 21 May 2008 (UTC)
thread_title:  <code>printf</code> in Java 

message: The section on precision uses "*" in the beginning of the sentence, shouldn't it be ".*" instead? The flag ".*" is used in the example printf statement in the second sentence. 64.94.55.231 (talk) 18:02, 16 June 2008 (UTC)
thread_title:  Precision 

message: I want to replace code like the following (in Java, but PHP and C and C# and C++ are also important ;-) ...
 System.out.println("Your age is " + age + " and your weight is " + weight);
with something like this ...
 System.out.println("Your age is %int and your weight is %int", age, weight);
Please construct a few examples like this, for the weary programmer-in-a-hurry who doesn't want to wade through several paragraphs of formal specifications and historical detail. Just tell me how to use this functionality. --Uncle Ed (talk) 16:11, 23 August 2008 (UTC)
replies: text: Would %d (for decimal integer) do it? And why doesn't Wikipedia have an article on the decimal integer (if only as a formatting concept)? --Uncle Ed (talk) 16:20, 23 August 2008 (UTC)

text: There's a pretty good example in the image at the head of the article. Honestly, though, I think the article needs a major overhaul. -- BenRG (talk) 17:43, 23 August 2008 (UTC)
replies: text: Yes, I saw that. Let's overhaul the article together, shall we? --Uncle Ed (talk) 00:50, 26 August 2008 (UTC)
thread_title: Call for examples

message: There is distinct controversy over the use of printf in languages that just pass an untyped buffer around and expect the developer to give clear instructions in the other parameters regarding how to divide it up. C and C++ do this, but I don't know how many other languages provide direct interaction with memory the way they do. This becomes especially problematic with C++'s pointer-redirection. It is a common issue to edit the format portion of a printf statement and an integer be accidentally cast as a pointer to string, resulting in crashes that only occur under odd conditions.
Is this something that can be included? Regardless of whether this belongs in the general article on printf, I'd still like to suggest that risks, gotchas, and work-arounds be moved to a discrete section of this article. Robert Rapplean (talk) 18:35, 8 August 2009 (UTC)
thread_title:  Controversies? 

message: I don't understand why any one would be interested in the historical information regarding the fact that Fortran and COBOL and Multics  don't have printf.  —Preceding unsigned comment.
I agree.  The way Fortran, COBOL, Lisp etc print things has nothing to do with the C's printf statement.  Perl, Python, Java etc are relevant as their printing is based on the C function.  Algol is probably OK as it was the precursor. AndrewWPhillips (talk)
Good idea to show how languages that don't have printf do formatting and,
in anticipation of perhaps, moving some of this article to formatting article.
DG12 (talk) 18:19, 17 October 2011 (UTC)
thread_title:  non-printf info extraneous 

message: In Windows, the *printf functions support %Z and %wZ respectively, corresponding to pointers to the sort-of-documented Windows NT types "ANSI_STRING" and "UNICODE_STRING" respectively.  Is it worthwhile mentioning this?  —Preceding unsigned comment added by Myria (talk • contribs) 21:53, 15 March 2010 (UTC)
thread_title:  %Z and %wZ in Win32 

message: should we have another page for sprintf with all its args? Umar1996 (talk) 13:53, 27 September 2010 (UTC)
thread_title:  sprintf 

message: The article implies that snprintf was only added to C in 1999.  On the contrary it is very old.  It first appeared in UNIX compilers before the first C standard (1989) but after that most compilers renamed it to _snprintf as it was not in the standard library.
AndrewWPhillips (talk) 04:46, 9 November 2010 (UTC)
thread_title:  snprintf is very old 

message: Is it correct that a string cannot be truncated (including trailing spaces) using width (or anything else in the format)? For example  
sssm="my shortname   " ; sssy="your verylongname    ";
printf ("~123456789ABC~\n~%12s~\n~%12s~", sssm,sssy) 
outputs 
~123456789ABC~
~my shortname   ~
~your verylongname    ~  — Preceding unsigned comment added by DGerman (talk • contribs) 01:12, 15 October 2011 (UTC)
replies: text: Where does it say that? The width option is for setting a lower limit on the width by padding the output, so it is true that it does not do truncation. The precision option can be used truncate strings, although I seem to remember that some C standard (but apparently not POSIX) still requires that they always be null-terminated, even if you know truncation will always happen.  Vadmium (talk, contribs) 02:55, 15 October 2011 (UTC)
thread_title: width

message: many languages on the list do not literally have a "printf" intrinsic, and most any language has some more or less roundabout mechanism to achieve similar results. So what exactly is the point of this list?  — Preceding unsigned comment added by 75.186.86.53 (talk) 23:34, 25 March 2015 (UTC)
replies: text: THANK YOU!!!! Can we maybe delete all the Fortran and other stuff too? I suppose an article of "how text output was done in various programming languages" might be interesting but it this is not that article.Spitzak (talk) 18:49, 9 November 2016 (UTC)
replies: text: I agree, the article should focus on printf specifically.  The superfluous examples were removed.  Ziphit (talk) 19:35, 10 November 2016 (UTC)
thread_title:  Programming languages with printf   -- literally? what is this list. 

message: There's probably a mathematical explanation for why the # format "flag" character doesn't display 0 like other values, but it makes displaying lists of numbers considerably more complicated, if not slower.  I think this would be a good page to explain why this decision was made (I can't find it).
Tmellman (talk) 11:14, 12 September 2016 (UTC)
thread_title:  Could somebody please explain the rationale for treating 0 values differently? 

message: The redirect %d has been listed at redirects for discussion to determine whether its use and function meets the redirect guidelines. Readers of this page are welcome to comment on this redirect at  until a consensus is reached.  Nickps (talk) 14:00, 18 March 2024 (UTC)
thread_title:  "[[:%d]]" listed at [[Wikipedia:Redirects for discussion|Redirects for discussion]] 

message: The redirect Format string has been listed at redirects for discussion to determine whether its use and function meets the redirect guidelines. Readers of this page are welcome to comment on this redirect at  until a consensus is reached.  Nickps (talk) 14:00, 18 March 2024 (UTC)
replies: text: I ended up renominating this one, so you should comment again if you already did. Nickps (talk) 01:10, 21 March 2024 (UTC)
thread_title:  "[[:Format string]]" listed at [[Wikipedia:Redirects for discussion|Redirects for discussion]] 

message: The redirect Placeholder (Computing) has been listed at redirects for discussion to determine whether its use and function meets the redirect guidelines. Readers of this page are welcome to comment on this redirect at  until a consensus is reached.  Nickps (talk) 19:08, 18 March 2024 (UTC)
thread_title:  "[[:Placeholder (Computing)]]" listed at [[Wikipedia:Redirects for discussion|Redirects for discussion]] 

message: In response to removal of Tabular output by @Spitzak who says: Removed this, it is hardly a "limitation", the solution is obvious, and there isn't any better method. The described behavior of the function is definitely what I'd call a limitation, what is that obvious solution? and surely there is a better way. Other than that I agree with you ;)
I recently moved this section from Vulnerabilities to a new section Limitations, since that behavior is a limitation and is not a vulnerability.
But, I'm not going to revert the change since WP doesn't need to be a programmer's guide for the standard C library.
Maybe should describe this behavior under Width field. Stevebroshar (talk) 12:40, 20 April 2024 (UTC)
replies: text: The obvious solution is that the programmer has to decide what to do if the value is too big to fit in the allotted width. One approach would be to use something like  (with spaces) instead of . However, the how-to section was not appropriate at Wikipedia regardless of the details. Johnuniq (talk) 02:19, 21 April 2024 (UTC)
replies: text: That the programmer has to decide what to do is obvious yes, but not what I'd call a solution. Your proposed solution is not what I'd call obvious. ... I think your proposed solution _could_ solve the problem, but it might not. If a value doesn't fit in width 8, then surely it won't fit in 7. Your solution ensures that there is whitespace between values, but the output won't be tabular. There are two issues: tabular format and space between values. I'd say the problem is challenging and there is no obvious solution. ... But, beyond that I disagree that there is an obvious answer, I have an issue with the word obvious. When someone says something is obvious, it sounds like they are saying they are smarter than anyone who does not see that solution on their own. IMO the world needs more compassion. ... WRT how-to: the first half describes a limitation. The second half is about how to work around the limitation. If we don't want how-to then could have removed the how-to part. Why remove the limitation part? ... IMO this article is sorely missing info on limitations since printf has a list of limitations arm long. Stevebroshar (talk) 10:25, 21 April 2024 (UTC)
replies: text: I consider the solution obvious, especially if you just ask the programmer "what if you wanted a different character than space to separate the columns". And this is not a limitation of printf, it is a limitation of devices that are fixed width and cannot overprint a digit with some other symbol.Spitzak (talk) 10:44, 22 April 2024 (UTC)
replies: text: Your understanding of obvious is different than mine. ... your question to the programmer makes no sense to me since your proposed solution is to use a space. ... the issue is more about formatting than output devices ... overprinting one character on another is a solution? Stevebroshar (talk) 12:50, 25 April 2024 (UTC)
thread_title:  Tabular output limitation