-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathft_printf_unsigned.c
More file actions
55 lines (51 loc) · 1.44 KB
/
Copy pathft_printf_unsigned.c
File metadata and controls
55 lines (51 loc) · 1.44 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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_printf_unsigned.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: schahid <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2021/12/07 14:59:58 by schahid #+# #+# */
/* Updated: 2021/12/08 18:11:05 by schahid ### ########.fr */
/* */
/* ************************************************************************** */
#include "ft_printf.h"
char *unsigned_itoa(unsigned int nb)
{
unsigned int nbr;
char *num;
int i;
nbr = nb;
i = 0 ;
while (nb)
{
i++ ;
nb = nb / 10 ;
}
num = (char *)malloc(sizeof(char) * (i + 1));
if (!num)
return (NULL);
num[i] = '\0';
while (nbr)
{
num[i - 1] = nbr % 10 + 48 ;
nbr = nbr / 10 ;
i-- ;
}
return (num);
}
int printunsigned(unsigned int nb)
{
char *num;
int printlen;
printlen = 0 ;
if (!nb)
printlen += write(1, "0", 1);
else
{
num = unsigned_itoa(nb);
printlen += printstr(num);
free(num);
}
return (printlen);
}