Sprintf
A formatted-output function or operation that converts supplied values according to a format specification and produces formatted character data.
Modern C
sprintf is a C standard library function that formats output into a character array without providing a destination-size bound.
- How it is used
- Formats numbers and other values into a character array while constructing text in memory.
- How deep it goes
- Explains formatting, termination, return length, and overflow risk, while deferring bounded construction to snprintf.
- Examples
- Demonstrates sprintnumbers, repeated number formatting, separator copying, and the format string "%#zX".
- What you can do after
- Apply it via the C standard library while recognizing when bounded formatting is required.
Modern C, Third Edition
sprintf is a C standard-library function that formats converted values into a character array without imposing a destination-size limit.
- How it is used
- Formats parsed numbers into a string while advancing a destination-buffer pointer.
- How deep it goes
- Explains formatting, termination, return length, and overflow risk, then defers bounded output to snprintf.
- Examples
- Uses sprintnumbers to format numbers, insert separators, advance a buffer pointer, and append a newline.
- What you can do after
- Apply sprintf when the destination capacity is already known, and select snprintf for unknown-length output.
Related concepts
- snprintfalternative to · snprintf is a C standard-library function that formats output into a character array within a specified size limit and returns the required output length.
- string formattingimplements · String formatting is the construction of text from values according to a specified format or template.
- String functionproduces · The JavaScript String function converts a value to its textual string representation.
- printfuses · printf is a formatted-output API that uses a format specification and supplied values to produce text, either returning it or writing it to an output destination.
- templatealternative to · A template is a reusable structure with fixed elements and variable parts for creating or generating similar content, outputs, or artifacts.
These guides are generated from the text of Manning books by Manning's knowledge graph and link to the sections they draw on. The full books are available on liveBook and at manning.com.

