Sprintf dont work!

Hello, I am using e2 studio compiler and RL78 G13 MCU.


I have a program where I get a floating value. But at the moment of wanting to observe it via serial and use the expression

sprintf (temp_Buff, "% f", Spare_Power);

The program freezes and there is no way out of there.

Translated with Google translator hahaha

  • Hi EduardoBorgiaE,

    I did try to reproduce the raised issue but, as far as I've seen, sprintf() implementation does work as specified under the latest RL78's CC-RL compiler.

    Yet so, I'd recommend for you to consider using snprintf() instead for such operations, as it helps to prevent buffer overflows.

    I've also noticed a <blank_space> between % and f within your formatting string. It is actually %f (altogether).

    Here is the minimal code snippet which I used when trying to reproduce the issue alongside its resulting buffer.

  • I am using kpit gnu rl78-elf toolchain.

    I have tried again but the system dies. I solved it using a function ftoa to do the conversion. Thanks for helping brother.
  • Hi Romeo,

    Thanks for this clarification. I could not reproduce the issue in the latest GNURL78 toolchain as well (v4.9.2.201703).

    The sprintf() function from the optimized library does work. The sprintf() from the newlib does work.

    I am unable to reproduce this issue at this end. Feel free to share the minimal code snippet which reproduces the issue.

    For issues specific to the GCC libraries function implementations for Renesas MCUs I'd also recommend this forum


    from the maintainers of the Renesas GCC toolchains. 

    Good luck.

  • unsigned char str[20];
    unsigned char *ftos(float f,int precision)
    float ff;
    ff = f;
    int a,b,c,k,l=0,m,i=0;
    // check for negetive float
    a=f; // extracting whole number
    f-=a; // extracting decimal part
    k = precision;
    // number of digits in whole number
    l = pow(10,k);
    m = a/l;
    // number of digits in whole number are k+1

    extracting most significant digit i.e. right most digit , and concatenating to string
    obtained as quotient by dividing number by 10^k where k = (number of digit -1)
    b = pow(10,l-1);
    c = a/b;
    str[i++] = '.';
    /* extracting decimal digits till precision */
    b = f;
    return str;


    /////// I add that it has certain limitations in terms of some values but it suits my need! Greetings.