Repository navigation
Expand file tree
/
Copy pathft_print_unsigned.c
More file actions
62 lines (55 loc) · 1.49 KB
/
Copy pathft_print_unsigned.c
File metadata and controls
62 lines (55 loc) · 1.49 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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_print_unsigned.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: mrichard <mrichard@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/11/03 22:09:41 by marcela #+# #+# */
/* Updated: 2022/11/18 16:12:28 by mrichard ### ########.fr */
/* */
/* ************************************************************************** */
#include "ft_printf.h"
int ft_num_len(unsigned int num)
{
int len;
len = 0;
while (num != 0)
{
len++;
num /= 10;
}
return (len);
}
char *ft_uitoa(unsigned int n)
{
char *num;
int len;
len = ft_num_len(n);
num = (char *)malloc((len + 1) * sizeof(char));
if (!num)
return (NULL);
num[len] = '\0';
while (n != 0)
{
num[len - 1] = n % 10 + 48;
n = n / 10;
len--;
}
return (num);
}
int ft_print_unsigned(unsigned int n)
{
int length;
char *num;
length = 0;
if (n == 0)
length += write(1, "0", 1);
else
{
num = ft_uitoa(n);
length += ft_print_str(num);
free(num);
}
return (length);
}