-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathft_putunbr.c
More file actions
48 lines (44 loc) · 1.42 KB
/
ft_putunbr.c
File metadata and controls
48 lines (44 loc) · 1.42 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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_putunbr.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: thuynguy <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/11/29 22:10:48 by thuynguy #+# #+# */
/* Updated: 2022/11/29 22:33:08 by thuynguy ### ########.fr */
/* */
/* ************************************************************************** */
#include "ft_printf.h"
char *ft_uitoa(unsigned int nbr)
{
char *numstr;
int len;
len = print_len_num(nbr, 10);
numstr = (char *) malloc(sizeof(char) * (len + 1));
if (!numstr)
return (0);
numstr[len--] = '\0';
while (len >= 0)
{
numstr[len] = nbr % 10 + '0';
nbr = nbr / 10;
len--;
}
return (numstr);
}
int ft_putunbr(int num)
{
int print_len;
char *numstr;
if (num == 0)
return (ft_putchar('0'));
print_len = 0;
numstr = ft_uitoa(num);
if (numstr)
{
print_len += ft_putstr(numstr);
free(numstr);
}
return (print_len);
}