This thread has been locked.
If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.
Tool/software: TI C/C++ Compiler
Hi ,
I'm having trouble using sprintf function with code composer studio 8 and c compiler v 6.2.11 . I'm tryng to build a string in this way :
sprintf((char *)wifi_info.jsonTxBuffer, "{\"cmdId\":%d,\"quote\":%u,\"speed\":%d,\"state\":%d,\"errorMask\":%d}", CMDGETPDO, sumFir, velMandToTransmit, stateByte, errMask);
but in the result buffer the variables are printed shifted. For example the correct result will be the string:
{"cmdId":0, "quote":292, "speed":0, "stateByte":0,"errMask":340}
instead what i get is:
{"cmdId":0, "quote":0, "speed":0, "stateByte":292,"errMask":0} or sometimes in the second %d character there's a random number.
If i use it with fixed values instead of variables it works fine ( sprintf((char *)wifi_info.jsonTxBuffer, "{\"cmdId\":%d,\"quote\":%u,\"speed\":%d,\"state\":%d,\"errorMask\":%d}", 10, 11, 12, 13, 14); )
I set the stack and heap size , and also enabled --printf_support=minimal compiler option (stdio.h is also included).
Does anyone experienced the same issue?
Regards.
Fabio
When using --print_support-minimal, the format specifier %u is not supported. Change it to %d. I cannot guarantee this fixes the problem. But it should help.
Thanks and regards,
-George