-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathft_itoa.c
40 lines (37 loc) · 1.31 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
36
37
38
39
40
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_itoa.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: sgrindhe <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2018/07/17 09:37:09 by sgrindhe #+# #+# */
/* Updated: 2018/08/06 00:09:38 by sgrindhe ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
char *ft_itoa(int nb)
{
char *str;
str = (char*)malloc(sizeof(char) * 2);
if (str == NULL)
return (NULL);
if (nb == -2147483648)
{
return (ft_strdup("-2147483648"));
}
if (nb < 0)
{
str[0] = '-';
str[1] = '\0';
str = ft_strjoin(str, ft_itoa(-nb));
}
else if (nb >= 10)
str = ft_strjoin(ft_itoa(nb / 10), ft_itoa(nb % 10));
else if (nb < 10)
{
str[0] = nb + '0';
str[1] = '\0';
}
return (str);
}