-
Notifications
You must be signed in to change notification settings - Fork 0
/
ft_verifie.c
99 lines (90 loc) · 2.02 KB
/
ft_verifie.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
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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* check.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: bel-bouz <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2019/01/14 21:22:36 by bel-bouz #+# #+# */
/* Updated: 2019/01/14 21:22:39 by bel-bouz ### ########.fr */
/* */
/* ************************************************************************** */
#include "swap.h"
int check_double(t_pile **pile, int double_, int len)
{
t_pile *last;
int i;
int j;
last = *pile;
i = 0;
j = 0;
while (len > 0)
{
if (double_ == (*pile)->value)
{
if (j == 1)
return (0);
j = 1;
}
*pile = (*pile)->prec;
len--;
}
*pile = last;
return (1);
}
int check(t_pile **pile, int len)
{
t_pile *last;
t_pile **tmp;
int i;
tmp = pile;
last = *pile;
i = 0;
while (len > 1)
{
if (check_double(tmp, (*pile)->value, len) == 0)
return (0);
*pile = (*pile)->prec;
len--;
}
*pile = last;
return (1);
}
int ft_atoi_check(const char *str)
{
int i;
long long int num;
int bl;
i = 0;
num = 0;
bl = 0;
if (*(str + i) == '-' || *(str + i) == '+')
{
bl = 1;
i++;
}
while (str[i] && str[i] >= '0' && str[i] <= '9')
{
num = num * 10 + (str[i] - '0');
if (num > 2147483647)
return (0);
i++;
}
if (i != (int)ft_strlen(str) || (i == 1 && bl == 1))
return (0);
return (1);
}
void ft_putnbr(int nb)
{
unsigned int nbr;
if (nb < 0)
{
ft_putchar('-');
nbr = nb * -1;
}
else
nbr = nb;
if (nbr >= 10)
ft_putnbr(nbr / 10);
ft_putchar(nbr % 10 + 48);
}