-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathft_itoa.c
37 lines (34 loc) · 1.3 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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_itoa.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: nmafa <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2019/06/27 13:54:42 by nmafa #+# #+# */
/* Updated: 2019/06/29 04:45:10 by nmafa ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
char *ft_itoa(int n)
{
char *str;
if (!(str = (char *)malloc(sizeof(char) * 2)))
return (NULL);
if (n == -2147483648)
return (ft_strcpy(str, "-2147483648"));
if (n < 0)
{
str[0] = '-';
str[1] = '\0';
str = ft_strjoin(str, ft_itoa(-n));
}
else if (n >= 10)
str = ft_strjoin(ft_itoa(n / 10), ft_itoa(n % 10));
else if (n < 10 && n >= 0)
{
str[0] = n + '0';
str[1] = '\0';
}
return (str);
}