-
Notifications
You must be signed in to change notification settings - Fork 0
/
ft_itoa.c
executable file
·35 lines (32 loc) · 1.21 KB
/
ft_itoa.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_itoa.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: ioleksiu <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2016/12/22 14:53:13 by ioleksiu #+# #+# */
/* Updated: 2016/12/28 18:37:58 by ioleksiu ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
char *ft_itoa(int n)
{
char *area;
int len;
unsigned int num;
len = 0;
len = ft_count_int(n);
if (!(area = (char *)malloc((len + 1))))
return (0);
area[len--] = '\0';
num = ft_int_min(n);
while (len >= 0)
{
area[len--] = num % 10 + 48;
num = num / 10;
}
if (n < 0)
area[0] = '-';
return (area);
}