27

I tried looking it up on google and wikipedia but couldn't find an answer... Does anyone know what 'sprintf' or 'printf' stands for? Is it an abbreviation for something???

Thanks

1
  • 1
    Lots of their functions have weird names. You'd think they would be more organised. Feb 20, 2010 at 0:27

3 Answers 3

36

String PRINT Format(ed).

I.e. print to string using a given format.

0
30

The various members of the printf family, derived from C where they first appeared (though they hark back to the olden days of BCPL's writef call along that particular lineage), include:

printf    - print formatted (to standard output).
fprintf   - file printf (to a file handle).
sprintf   - string printf (to a string).
snprintf  - sprintf with added overflow protection.

In addition, there are variants of those starting with v (as in vsnprintf) which can take variable arguments like printf itself.

By that I mean that they pass around a varargs argument rather than a series of arguments, allowing you to write your own printf-like function. I've used this before when developing logging libraries in the past.

3

sprintf originates from C. Refer to e.g.

http://www.cplusplus.com/reference/clibrary/cstdio/sprintf/

where it says:

Writes into the array pointed by str a C string ...

thus: s(tring)printf(ormatted)

1
  • @hobodave - to be fair, he did add the cross-reference link. I've had cases here where I've spent a few minutes getting references to put in an answer and in that time someone else has posted a similar answer without any references. Both answers are good.
    – Spudley
    Nov 6, 2010 at 14:13

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.