Chapter 14. Formatting

The standard C library functions printf, fprintf, and vprintf format data for output, and sprintf and vsprintf format data into strings. These functions are called with a format string and a list of arguments whose values are to be formatted. Formatting is controlled by conversion specifiers of the form %c embedded in the format string; the ith occurrence of %c describes how to format the ith argument in the list of arguments that follow the format string. The other characters are copied verbatim. For example, if name is the string Array and count is 8,

  sprintf(buf, "The %s interface has %d functions\n",
      name, count)

fills buf with the string "The Array interface has 8 functions\n", where \n denotes a new-line character, ...

Get C Interfaces and Implementations: Techniques for Creating Reusable Software now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.