maxishell
Implementation of a shell for Linux-like systems
Loading...
Searching...
No Matches
ft_atoi.c
Go to the documentation of this file.
1/* ************************************************************************** */
2/* */
3/* ::: :::::::: */
4/* ft_atoi.c :+: :+: :+: */
5/* +:+ +:+ +:+ */
6/* By: rmikhayl <rmikhayl@student.42london.c +#+ +:+ +#+ */
7/* +#+#+#+#+#+ +#+ */
8/* Created: 2023/12/17 17:25:27 by rmikhayl #+# #+# */
9/* Updated: 2023/12/17 17:25:27 by rmikhayl ### ########.fr */
10/* */
11/* ************************************************************************** */
12
13/* *************************** ft_atoi ************************************** */
14/* Converts the string 'str' to an integer, taking into account the sign. */
15/* */
16/* In layman's terms: It's like translating a number written in text into a */
17/* numerical value. */
18/* ************************************************************************** */
19
20int ft_atoi(char *str)
21{
22 int sign;
23 int num;
24 int i;
25
26 sign = 1;
27 num = 0;
28 i = 0;
29 while (str[i] == ' ' || (str[i] >= '\t' && str[i] <= '\r'))
30 i++;
31 if (str[i] == '-' || str[i] == '+')
32 {
33 if (str[i] == '-')
34 {
35 sign = -1;
36 }
37 i++;
38 }
39 while (str[i] >= '0' && str[i] <= '9')
40 {
41 num = num * 10 + (str[i] - '0');
42 i++;
43 }
44 return (sign * num);
45}
int ft_atoi(char *str)
Definition ft_atoi.c:20