Print formatted data to a string: how to use sprintf
#include <stdio.h>
int main ()
{
char buffer [50];
int n, a = 50, b = 37;
n = sprintf (buffer, "%d plus %d is %d", a, b, a + b);
printf ("[%s] is a %d chars string\n", buffer, n);
return 0;
}
Related examples in the same category