### Question 13.1

How can I convert numbers to strings (the opposite of `atoi`)? Is there an `itoa` function?

Just use `sprintf`. (Don't worry that `sprintf` may be overkill, potentially wasting run time or code space; it works well in practice.) See the examples in the answer to question 7.5; see also question 12.21.

You can obviously use `sprintf` to convert `long` or floating-point numbers to strings as well (using `%ld` or `%f)`.

References: K&R1 Sec. 3.6 p. 60
K&R2 Sec. 3.6 p. 64

Read sequentially: prev next up top

This page by Steve Summit // Copyright 1995 // mail feedback