O'Reilly logo

Advanced Mac OS X Programming: The Big Nerd Ranch Guide by Mark Dalrymple

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Formatted I/O

The printf family of calls lives under standard / buffered I/O because they write out to FILE streams, either explicitly or implicitly. sprintf and snprintf write to a buffer, but they have the same syntax as their I/O companions.

int printf (const char *format, ...);

int fprintf (FILE *stream, const char *format, ...);

int sprintf (char *str, const char *format, ...);

int snprintf (char *str, size_t size, const char *format, ...);

int asprintf (char **ret, const char *format, ...);

printf() writes to stdout. fprintf() writes to any FILE. sprintf() writes into a buffer, while snprintf() writes into a buffer but is given the amount of space it can write in. Always use snprintf() instead of sprintf(). There is no prevention of buffer ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required