O'Reilly logo

Exceptional C++ Style 40 New Engineering Puzzles, Programming Problems, and Solutions by Herb Sutter

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 2. The String Formatters of Manor Farm, Part 1: sprintf

Difficulty: 3

In this Item and the next, an Orwellian look at the mysteries of sprintf and why the alternatives are always (yes, always) better.

Solution

 

“All animals are equal, but some animals are more equal than others.”

 
 --George Orwell, Animal Farm
  1. What is sprintf? Name as many standard alternatives to sprintf as you can.

Consider the following C code that uses sprintf to convert an integer value to a human-readable string representation, perhaps for output on a report or in a GUI window:

// Example 2-1: Stringizing ...

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