rendered paste body/*
** itoa.c for Project in /home/gnaphron
**
** Made by gnaphron
** Login <gnaphron@epita.fr>
**
** Started on Tue 06 Feb 2007 08:49:40 PM CET gnaphron
** Last update Tue 06 Feb 2007 09:11:06 PM CET gnaphron
*/
#include <stdio.h>
#include <string.h>
#include <unistd.h>
#include <stdlib.h>
char *itoa(int value)
{
int cpyvalue = 0;
int len = 0;
char *str;
//We assume that value > 0
while (value)
{
cpyvalue *= 10;
cpyvalue += value % 10;
value /= 10;
len++;
}
str = malloc(len + 1);
memset(str, 0, len + 2);
len = 0;
while (cpyvalue > 0)
{
str[len] = (cpyvalue % 10) + '0' ;
cpyvalue /= 10;
len++;
}
return (str);
}
int main(int argc, char* argv)
{
printf ("%s\n", itoa(123));
return 0;
}