-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathft_atoi.c
More file actions
47 lines (44 loc) · 1.33 KB
/
ft_atoi.c
File metadata and controls
47 lines (44 loc) · 1.33 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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_atoi.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: sudaniel <sudaniel@student.42heilbronn.de +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/10/10 13:15:26 by sudaniel #+# #+# */
/* Updated: 2024/10/10 14:29:05 by sudaniel ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
int ft_atoi(const char *str)
{
int sign;
int num;
num = 0;
sign = 1;
while ((*str >= 9 && *str <= 13) || *str == 32)
str++;
if (*str == '-' || *str == '+')
{
if (*str == '-')
sign = -1;
str++;
}
while (*str >= '0' && *str <= '9')
{
num *= 10;
num += (*str - '0');
str++;
}
return (sign * num);
}
/*
int main(void)
{
char *s = " \t\n1234";
int n = ft_atoi(s);
int m = atoi(s);
printf("%d\n%d\n", n, m);
return (0);
}
*/