itead / ITEADLIB_Arduino_Nextion

MIT License
329 stars 318 forks source link

utoa not included in standard C/C++ lib #38

Open hahnicity opened 7 years ago

hahnicity commented 7 years ago

We're working on an Intel Edison which uses GNU libc/c++ and we've been trying to compile our nextion code but it doesn't work because utoa is not included in the base C/C++ lib. The only workaround I can currently think of is to modify the library to include utoa. Do you have any other suggestions?

DrStein99 commented 7 years ago

I modified my library to use itoa, since the number fields on the display will display signed integers - since I actually need to know negative or positive values on my readouts. I suggest modifying the function to channel the data however it works for you.

Pharap commented 5 years ago

Sorry to rake up such an old issue, but utoa (nonstandard) can be implemented with sprintf/std::sprintf (standard):

char * utoa(unsigned int value, char * str, int radix)
{
    const char * format = nullptr;

    switch(radix)
    {
        case 8:
            format = "%o";
            break;
        case 10:
            format = "%u";
            break;
        case 16:
            format = "%x";
            break;
    }

    if(format == nullptr)
        return str;

    int size = std::sprintf(str, format, value);
    return &str[size];
}