mirror of
https://github.com/iritmaximus/os.git
synced 2026-10-12 19:13:36 +03:00
24 lines
385 B
C
24 lines
385 B
C
#include <stdio.h>
|
|
|
|
char* itoa(int value, char* str, int base)
|
|
{
|
|
// check for incorrect base
|
|
if (base < 2 || base > 36)
|
|
{
|
|
printf("\n ERROR: Incorrect base\n");
|
|
return '\0';
|
|
}
|
|
|
|
char num[] = "0123456789abcdefghijklmnopqrstuvwxyz";
|
|
|
|
while (value/base > 1)
|
|
{
|
|
// TODO does this need a check for str_len?
|
|
*str = num[value % base];
|
|
str++;
|
|
value /= base;
|
|
}
|
|
|
|
return str;
|
|
}
|