-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathft_putnbr_base.c
More file actions
78 lines (66 loc) · 899 Bytes
/
ft_putnbr_base.c
File metadata and controls
78 lines (66 loc) · 899 Bytes
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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
#include <unistd.h>
int ft_strlen(char *str)
{
int i;
i = 0;
while(str[i])
i++;
return(i);
}
void ft_putchar(char c)
{
write(1, &c, 1);
}
void ft_putnbr(int nb, int size, char *base)
{
int i;
i = 0;
if(nb > 9)
{
ft_putnbr((nb / size), size, base);
ft_putchar(base[nb % size]);
}
if(nb < 9)
{
ft_putchar(base[nb]);
}
}
int ft_check_base(char *str)
{
int i;
int j;
i = 0;
while(str[i])
{
j = i + 1;
if(str[i] == '+' || str[i] == '-'
|| str[0] == '\0' || str[1] == '\0')
return(1);
while(str[j])
{
if(str[j] == str[i])
return(1);
j++;
}
i++;
}
return(0);
}
void ft_putnbr_base(int nbr, char *base)
{
int i;
int R;
i = 0;
R = 0;
if(ft_check_base(base) == 1)
return;
ft_putnbr(nbr,ft_strlen(base), base);
}
#include <stdio.h>
int main ()
{
char base[17] = "theo";
int nbr = 14711;
ft_putnbr_base(nbr, base);
return(0);
}