Difference between revisions of "Printf family"
From Maths
(Created page with "{{DISPLAYTITLE:{{cs|printf}} family}} : Not to be confused with ''printf (program)'' __TOC__ ==Description== The {{cs|printf()}} family of functions are used for ''formatt...") |
(No difference)
|
Latest revision as of 09:46, 1 October 2017
- Not to be confused with printf (program)
Contents
Description
The printf() family of functions are used for formatting strings, in fact printf is short for "print formatted", the family has 2 distinct branches:
- First, defined in stdio.h[1]
- int printf(const char* format, ...)
- int fprintf(FILE* file, const char* format, ...)
- int snprintf(char* target, size_t capacity const char* format, ...)
- int sprintf(char* target, const char* format, ...)[Note 1] Warning:do not use
- Second, defined in stdarg.h - these are identical except they use C varadics, via va_list
Return values
Implementation notes
TODO: Explain that printf can't be a macro using fprintf as the standard specifies "functions" (so taking address must work)
TODO: Explain though, how any implementation written by a sane person, would make printf use vfprintf(stdout,...) "" for the string ones
Introductory examples
Formats
Examples
Notes
- ↑ Do not use this, same reason as gets(char* target) - the size of the buffer isn't given, so it may write beyond it!
- ↑ Do not use this, same reason as gets(char* target) - the size of the buffer isn't given, so it may write beyond it!