The function sprintf() writes formatted data into a string.
It returns the buffer address.
char* sprintf(char *buffer,char *format, ...)
The available format codes are:
%d decimal integer
%c character
%s string
%f floating-point number in decimal notation
%lf double number
%x hex integer
Example:
void main ()
{
char buffer [50];
int
a=5,
b=3;
char
*n;
n = sprintf (buffer, "%d plus %d is %d", a, b, a+b);
printf ("buffer '%s' and n '%s' \n",buffer,n);
}
Output:
buffer '5 plus 3 is 8' and n '5 plus 3 is 8'