Re: convert int to string without using standard library (stdio.h)



websnarf@xxxxxxxxx wrote:
ceeques wrote:

I need to convert integer(and /short) to string without using sprintf

#include <string.h>

char * itostrappend (char * str, int v, int base) {
char d[2];
int rem = v % base;
if (rem < 0) {
strcat (str, "-");
v = -(v / base);
rem = -rem;
} else v /= base;
d[0] = "0123456789abcdefghijklmnopqrstuvwxyz"[rem];
d[1] = '\0';
if (v) str = itostrappend (str, v, base);
strcat (str, d);
return str + strlen (str);
}

void itostr (char * str, int v, int base) { /* Simple wrapper */
str[0] = '\0';
itostrappend (str, v, base);
}

Is that supposed to be a serious answer?

.



Relevant Pages