-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathft_atoi.c
48 lines (45 loc) · 1.49 KB
/
ft_atoi.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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_atoi.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: youel-id <youel-id@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/10/06 02:38:48 by youel-id #+# #+# */
/* Updated: 2022/10/24 21:26:12 by youel-id ### ########.fr */
/* */
/* ************************************************************************** */
#include<stdio.h>
#include"libft.h"
int ft_atoi(const char *str)
{
int i;
int res;
int n;
unsigned char *tmpstr;
tmpstr = ((unsigned char *)str);
i = 0;
n = 1;
res = 0;
while (tmpstr[i] == '\n' || tmpstr[i] == '\t' || tmpstr[i] == '\r'
|| tmpstr[i] == '\v' || tmpstr[i] == '\f' || tmpstr[i] == ' ')
i++;
if (tmpstr[i] == '-' || tmpstr[i] == '+')
{
if (tmpstr[i] == '-')
n = -1;
i++;
}
while ((tmpstr[i] >= '0' && tmpstr[i] <= '9'))
{
res = res * 10 + (tmpstr[i] - 48);
i++;
}
return ((res * n));
}
/*int main()
{
char str[] = " -+15156";
printf("%d",ft_atoi(str));
return(0);
}*/