-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathunsigned.c
40 lines (37 loc) · 1.23 KB
/
unsigned.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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* unsigned.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: asoudani <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/11/13 14:15:14 by asoudani #+# #+# */
/* Updated: 2024/11/14 21:16:45 by asoudani ### ########.fr */
/* */
/* ************************************************************************** */
#include "ft_printf.h"
int unsigned_int(unsigned int nb, int *nbr)
{
unsigned int i;
unsigned int n;
i = 1;
n = nb;
if (n == 0)
{
if (ft_putchar_fd('0', 1, nbr) == -1)
return (-1);
return (1);
}
while (i * 10 <= n)
{
i *= 10;
}
while (i > 0)
{
if (ft_putchar_fd((n / i) + '0', 1, nbr) == -1)
return (-1);
n %= i;
i /= 10;
}
return (1);
}