-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmy_atoi.c
68 lines (61 loc) · 1.07 KB
/
my_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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
/*
** my_atoi.c for a in /home/soucan_d/Projets/CPE_2015_Pushswap/final
**
** Made by DImitri Soucanye de Landevoisin
** Login <[email protected]>
**
** Started on Thu Nov 19 16:40:03 2015 DImitri Soucanye de Landevoisin
** Last update Thu Feb 18 00:33:38 2016 Dimitri
*/
#include <stdio.h>
#include <stdlib.h>
int count_nb_of_pipe(char **str, int line, int pipe)
{
int a;
pipe = 0;
a = -1;
while (str[line][++a] != '\0')
if (str[line][a] == '|')
pipe = pipe + 1;
return (pipe);
}
int parseur_str(const char *str)
{
int a;
a = 0;
if (str[a] == 0)
return (-1);
while (str[a] != 0)
{
if (str[a] > 47 && str[a] < 58)
a = a + 1;
else
return (-1);
}
return (0);
}
int my_atoi(const char *str)
{
int i;
int j;
int idx;
idx = 0;
i = 0;
j = 0;
if (parseur_str(str) == -1)
return (-1);
if (str[0] == '-')
{
idx = 1;
i = 1;
}
while (str[i] != 0)
{
if (str[i] >= '0' && str[i] <= '9')
j = j * 10 + str[i] - '0';
i = i + 1;
}
if (idx == 1)
j = j * -1;
return (j);
}