-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathft_putnbr_u.c
53 lines (48 loc) · 1.45 KB
/
ft_putnbr_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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_putnbr_u.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: alukyane <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2017/09/25 14:52:37 by alukyane #+# #+# */
/* Updated: 2017/09/25 14:52:39 by alukyane ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
static int ft_length(unsigned long long int n)
{
int length;
length = 0;
while (n != 0)
{
n /= 10;
length++;
}
return (length);
}
void ft_putnbr_u(unsigned long long int nb)
{
int j;
int *arr;
int f;
char *str;
arr = (int *)malloc(sizeof(int) * ft_length(nb));
j = 0;
if (nb == 0)
write(1, "0", 1);
while (nb != 0)
{
arr[j] = (nb % 10);
nb = nb / 10;
++j;
}
f = 0;
str = (char *)malloc(sizeof(char) * (j + 1));
while (j-- > 0)
str[f++] = arr[j] + '0';
str[f] = '\0';
write(1, str, ft_strlen(str));
free(str);
free(arr);
}