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

askedFeb 19, 2010 at 23:58
Mark's user avatar
1
  • 1
    Lots of their functions have weird names. You'd think they would be more organised.CommentedFeb 20, 2010 at 0:27

3 Answers3

36

String PRINT Format(ed).

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

answeredFeb 20, 2010 at 0:01
David Kanarek's user avatar
Sign up to request clarification or add additional context in comments.

Comments

31

The various members of theprintf family, derived from C where they first appeared (though they hark back to the olden days of BCPL'swritef 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 withv (as invsnprintf) which can take variable arguments likeprintf itself.

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

answeredFeb 20, 2010 at 0:20
paxdiablo's user avatar

Comments

4

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)

answeredFeb 20, 2010 at 0:05
S.Tayefeh's user avatar

1 Comment

@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.

Your Answer

Sign up orlog in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

By clicking “Post Your Answer”, you agree to ourterms of service and acknowledge you have read ourprivacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.