Repository navigation
Expand file tree
/
Copy pathft_atoi.c
More file actions
52 lines (48 loc) · 1.87 KB
/
Copy pathft_atoi.c
File metadata and controls
52 lines (48 loc) · 1.87 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
48
49
50
51
52
/* ************************************************************************** */
/* */
/* /#/ |#/|#| */
/* ft_atoi.c /#/ |/ |#| */
/* /#/ /#/ */
/* By: nepcohen <nepcohen@learner.42.tech> /#/ /#/ */
/* /#/____ |#| /| */
/* Created: 2026/06/02 15:48:27 by nepcohen |#######| |#|/#| */
/* Updated: 2026/06/02 20:40:01 by nepcohen |#| NEPH_ */
/* */
/* ************************************************************************** */
/* PROG ===================================================================== */
int ft_atoi(const char *nptr)
{
int count;
int result;
int symbol;
count = 0;
result = 0;
symbol = 1;
while (nptr[count] == 32 || (nptr[count] >= 9 && nptr[count] <= 13))
count++;
if (nptr[count] == '-' || nptr[count] == '+')
{
if (nptr[count] == '-')
symbol = -1;
count++;
}
while (nptr[count] >= '0' && nptr[count] <= '9')
{
result = result * 10 + (nptr[count] - '0');
count++;
}
return (symbol * result);
}
/* MAIN ===================================================================== */
#include <stdio.h>
int main(int argc, char **argv)
{
if (argc != 2)
printf("Merci de saisir un argument");
else
printf("INT : `%d`\n", ft_atoi(argv[1]));
return (0);
}
/* ========================================================================== */
/* END ============================================================= 42_ ==== */
/* ================================================================= NEPHCODE */