-
Notifications
You must be signed in to change notification settings - Fork 0
/
my_getnbr.c
50 lines (45 loc) · 859 Bytes
/
my_getnbr.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
/*
** my_getnbr.c for in /u/epitech_2012/brenne_t/cu/rendu/lib
**
** Made by thomas brennetot
** Login <[email protected]>
**
** Started on Fri Dec 28 15:41:28 2007 thomas brennetot
** Last update Fri Dec 28 15:41:31 2007 thomas brennetot
*/
#include "my.h"
int get_int(char *str, int signe)
{
int ret;
char c;
int bp_neg;
ret = 0;
c = *str;
bp_neg = -2147483647;
while (c >= '0' && c <= '9')
{
ret *= 10;
ret -= (c - '0');
if (ret > 0)
return (0);
c = *(++str);
}
if (signe > 0)
return ((ret >= bp_neg) ? (-1 * ret) : (0));
return (ret);
}
int my_getnbr(char *str)
{
int s;
char c;
s = 1;
c = *str;
while (c == '+' || c == '-')
{
s *= ((c == '-') ? (-1) : (1));
c = *(++str);
}
if (c >= '0' || c <= '9')
return (get_int(str, s));
return (0);
}