ardupilot/libraries/Desktop/support/ultoa_invert.c
Andrew Tridgell 6b583869c0 desktop: fixed ultoa_invert()
the string was backwards
2011-11-08 11:13:48 +11:00

25 lines
410 B
C

#include <stdio.h>
char * __ultoa_invert(unsigned long val, char *s, int base)
{
char tbuf[32];
char *p;
switch (base) {
case 8:
snprintf(tbuf, sizeof(tbuf), "%lo", val);
break;
case 16:
snprintf(tbuf, sizeof(tbuf), "%lx", val);
break;
case 10:
default:
snprintf(tbuf, sizeof(tbuf), "%lu", val);
break;
}
p = &tbuf[strlen(tbuf)-1];
while (p >= &tbuf[0]) {
*s++ = *p--;
}
return s;
}