Re: convert int to string without using standard library (stdio.h)
- From: "Old Wolf" <oldwolf@xxxxxxxxxxxxxx>
- Date: 17 Jul 2006 20:17:46 -0700
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?
.
- References:
- Prev by Date: Re: convert int to string without using standard library (stdio.h)
- Previous by thread: Re: convert int to string without using standard library (stdio.h)
- Next by thread: Re: convert int to string without using standard library (stdio.h)
- Index(es):
Relevant Pages
|