function opposite to atoi()?

Invisible Hippo picture Invisible Hippo · Dec 9, 2016 · Viewed 16.9k times · Source

I would like to convert an integer to a string like:

int a = 12345

coverts to

char b[6] = "12345"

basically the opposite of the atoi function that converts a string to an integer.

Answer

vonzhou picture vonzhou · Dec 9, 2016
#include <stdio.h>
int sprintf(char *str, const char *format, ...);

Example

char str[10]; 
sprintf(str,"%d", 12345);