-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathft_printf_putnbr_base_fd.c
More file actions
55 lines (50 loc) · 1.59 KB
/
ft_printf_putnbr_base_fd.c
File metadata and controls
55 lines (50 loc) · 1.59 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_putnbr_base_fd.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: aguiri <aguiri@student.42nice.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2021/11/04 00:18:45 by aguiri #+# #+# */
/* Updated: 2022/04/05 10:41:42 by aguiri ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
static int ft_printf_strlen_and_test(char *str)
{
unsigned int len;
unsigned int count;
len = 0;
count = 0;
while (str[len] != '\0')
{
if (str[len] == '+' || str[len] == '-')
return (0);
while (count < len)
{
if (str[count] == str[len])
return (0);
count++;
}
len++;
}
return (len);
}
int ft_printf_putnbr_base_fd(int nbr, char *base, int fd)
{
unsigned int len;
unsigned int div;
unsigned int mod;
int i;
i = 0;
len = ft_printf_strlen_and_test(base);
if (len == 0 || len == 1)
return (0);
div = (unsigned int) nbr;
mod = div % len;
div = div / len;
if (div != 0)
i += ft_printf_putnbr_base_fd(div, base, fd);
i += ft_printf_putchar_fd(base[mod], fd);
return (i);
}