-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathft_itoa.c
More file actions
42 lines (39 loc) · 1.37 KB
/
ft_itoa.c
File metadata and controls
42 lines (39 loc) · 1.37 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
42
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_itoa.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: vopolonc <vopolonc@student.unit.ua> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2018/11/11 14:08:41 by vopolonc #+# #+# */
/* Updated: 2019/01/12 13:38:46 by vopolonc ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
char *ft_itoa(long long n)
{
size_t j;
size_t k;
size_t temp;
long long i;
char *new;
temp = ft_is_minus(n);
k = ft_get_numb_len(n) + temp;
j = ft_get_numb_len(n) + temp;
i = n;
if (!(new = (char*)malloc(sizeof(char) * ft_int_len(n) + 1 + temp)))
return (NULL);
if (temp)
i = -i;
if ((temp && k == 2) || ((!temp) && k == 1))
new[--k] = i + '0';
while (i > 0)
{
new[--k] = i % 10 + '0';
i /= 10;
}
if (temp)
new[0] = '-';
new[j] = '\0';
return (new);
}