-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathft_itoa.c
More file actions
41 lines (38 loc) · 1.24 KB
/
ft_itoa.c
File metadata and controls
41 lines (38 loc) · 1.24 KB
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
41
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_itoa.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: sconstab <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2019/05/30 13:42:01 by sconstab #+# #+# */
/* Updated: 2019/06/06 13:41:22 by sconstab ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
char *ft_itoa(int n)
{
char *s;
size_t i;
size_t j;
size_t len;
i = 0;
j = 1;
len = ft_intlen(n);
if (n == 0)
return ("0");
if (!(s = malloc(len + 2 * sizeof(char))))
return (NULL);
if (n < 0)
{
j = -1;
s[--len] = '-';
}
while (i < len)
{
s[i++] = j * (n % 10) + '0';
n = n / 10;
}
s[i + 1] = '\0';
return (ft_strrev(s));
}