sprintf works just like printf, but outputs to a string, rather than stdout so
printf("Xposition %lf", x);
becomes
sprintf(s, "Xpostion %lf", x);
sprintf can produce buffer overflows, so better to use snprintf(), instead. e.g.
snprintf(s, 50, "Xposition %lf", x)
. More generally the signature for snprintf is
int snprintf(char *str, size_t size, const char *format, ...);
Note that snprintf() truncates output if it would exceed the designated size, but returns the number of chars it
would have written if enough space was available this means you can
if( snprintf(s, 50, "Xpostion %lf" x) > 50) {
}