Note that sprintf() does the opposite of a function like atoi() – where atoi()
converts a string into a number, sprintf() can be used to convert a number into
a string.
For example, the following code uses sprintf() to convert an integer into a
string of characters:

char result[100];int num =24;
sprintf( result,"%d", num );

This code is similar, except that it converts a floating-point number into an
array of characters:

char result[100];float fnum =3.14159;
sprintf( result,"%f", fnum );

Note that this function does not check the bounds of the buffer and therefore creates the risk of a buffer overflow.
A secure alternative is snprintf