Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
yabtaour
GitHub Repository: yabtaour/Philosophers-42
Path: blob/master/philo_bonus/ft_atoi_bonus.c
882 views
1
/* ************************************************************************** */
2
/* */
3
/* ::: :::::::: */
4
/* ft_atoi_bonus.c :+: :+: :+: */
5
/* +:+ +:+ +:+ */
6
/* By: yabtaour <[email protected]> +#+ +:+ +#+ */
7
/* +#+#+#+#+#+ +#+ */
8
/* Created: 2022/05/23 00:05:52 by yabtaour #+# #+# */
9
/* Updated: 2022/05/23 00:05:54 by yabtaour ### ########.fr */
10
/* */
11
/* ************************************************************************** */
12
#include "philosophers_bonus.h"
13
14
int ft_atoi(const char *str)
15
{
16
int i;
17
int sign;
18
int result;
19
20
sign = 1;
21
result = 0;
22
i = 0;
23
while (str[i] == '\t' || str[i] == '\n'
24
|| str[i] == '\r' || str[i] == '\v'
25
|| str[i] == ' ' || str[i] == '\f')
26
i++;
27
if (str[i] == '+')
28
i++;
29
else if (str[i] == '-')
30
{
31
sign *= -1;
32
i++;
33
}
34
while (str[i] >= '0' && str[i] <= '9')
35
{
36
result = (result * 10) + (str[i] - '0');
37
i++;
38
}
39
return (result * sign);
40
}
41
42