-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathft_atoi.c
More file actions
36 lines (34 loc) · 1.26 KB
/
Copy pathft_atoi.c
File metadata and controls
36 lines (34 loc) · 1.26 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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_atoi.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: sumdogan <sumdogan@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2026/01/21 10:49:29 by sumdogan #+# #+# */
/* Updated: 2026/01/28 20:04:17 by sumdogan ### ########.fr */
/* */
/* ************************************************************************** */
int ft_atoi(const char *nptr)
{
int i;
int main_number;
int flag;
i = 0;
main_number = 0;
flag = 1;
while ((nptr[i] == ' ') || (nptr[i] <= 13 && nptr[i] >= 9))
i++;
if ((nptr[i] == 43) || (nptr[i] == 45))
{
if (nptr[i] == 45)
flag *= -1;
i++;
}
while (nptr[i] <= 57 && nptr[i] >= 48)
{
main_number = main_number * 10 + nptr[i] - '0';
i++;
}
return (main_number * flag);
}