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.

TMS320F2800157: snprintf的问题

Part Number: TMS320F2800157


snprintf在把整数转为字符串时,可以正常转。

在把浮点数转为字符串时,会导致程序异常。

请问要把浮点数转为字符串,应该怎么办?

#define SPRINTF_BUFFER_SIZE 100
char sprintfBuffer[SPRINTF_BUFFER_SIZE] = {0};
snprintf(sprintfBuffer, SPRINTF_BUFFER_SIZE-1, "%d", 12);      // 把整数转为字符串,OK
snprintf(sprintfBuffer, SPRINTF_BUFFER_SIZE-1, "%f", 1.23);    // 把浮点数转为字符串,程序会异常