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.

snprintf

Hi All,

I am trying to use the snprintf function. However, when I am trying to convert a number (integer or a float) to a char array the software get stuck while running. Note that the code compiles without any errors or warnings.

Thanks in advance.

For example:

char buffer[50];

double meter=4.3;

snprintf(buffer, 50, "gal");  // works

snprintf(buffer, 50, "%09.1f gal", meter);  // doesn't work

  • Elad,

    I did a quick experiment and was able to recreate your issue.  The snprintf function comes from the C runtime compiler of the IDE tool you are using.

    I am guessing that the compiler doesn't support the float precision.  On my machine other types work, like %s, %c, %d, however the %f hangs the processor.

    Since this function comes from the toolchain runtime library, you would need to contact them for support on a possible work around for this.  This is likely a carry over from pre-floating point cores.

    Regards,
    Chris

  • Chris Rivera said:
    I did a quick experiment and was able to recreate your issue.

    What was stack size set to?

    The default stack size may not be sufficient, which can lead to a crash.

  • You are the stack size was the problem.

    The default was set to 512 but when I changed it to 2048 it started working just fine.

    Thanks!