O'Reilly logo

C Interfaces and Implementations: Techniques for Creating Reusable Software by David R. Hanson - Princeton University

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

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

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