-
Notifications
You must be signed in to change notification settings - Fork 0
/
ft_print_u.c
58 lines (54 loc) · 1.37 KB
/
ft_print_u.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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_print_u.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: ahaifoul <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2021/11/22 17:47:52 by ahaifoul #+# #+# */
/* Updated: 2021/11/23 12:11:23 by ahaifoul ### ########.fr */
/* */
/* ************************************************************************** */
#include "ft_printf.h"
long get_len(long nb)
{
int i;
i = 1;
if (nb < 0)
{
i++;
nb = -nb;
}
while (nb >= 10)
{
nb /= 10;
i++;
}
return (i);
}
int ft_itoa(long nb)
{
long i;
char *new;
i = get_len(nb);
new = (char *)malloc(sizeof (char) * (i + 1));
if (new == NULL)
return (0);
new[i] = '\0';
i--;
if (nb < 0)
{
nb *= -1;
new[0] = '-';
}
while (nb > 9)
{
new [i] = nb % 10 + 48;
nb = nb / 10;
i--;
}
new[i] = nb + 48;
i = ft_putstr(new);
free (new);
return (i);
}