Programming - cpueblo.com

itoa 의 구현


글쓴이 : 유광희 날짜 : 2002-05-13 (월) 16:50 조회 : 9190
char * ltoa (long val, char *buf, unsigned radix) { char *p; char *firstdig; char temp; unsigned digval; p = buf; if (radix == 10 && val < 0) { *p++ = '-'; val = (unsigned long)(-(long)val); } firstdig = p; do { digval = (unsigned) (val % radix); val /= radix; if (digval > 9) *p++ = (char) (digval - 10 + 'a'); else *p++ = (char) (digval + '0'); } while (val > 0); /* We now have the digit of the number in the buffer, but in reverse order. Thus we reverse them now. */ *p-- = '\\0'; do { temp = *p; *p = *firstdig; *firstdig = temp; --p; ++firstdig; } while (firstdig < p); return buf; } &lt;/XMP> </div> <!-- 테러 태그 방지용 --></xml>