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 |
What is
sprintf
? Name as many standard alternatives tosprintf
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 ...
Get Exceptional C++ Style 40 New Engineering Puzzles, Programming Problems, and Solutions now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.