-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathft_getnbr.c
30 lines (27 loc) · 1.22 KB
/
ft_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
/* ************************************************************************** */
/* LE - / */
/* / */
/* ft_getnbr.c .:: .:/ . .:: */
/* +:+:+ +: +: +:+:+ */
/* By: rcabotia <marvin@le-101.fr> +:+ +: +: +:+ */
/* #+# #+ #+ #+# */
/* Created: 2018/11/29 14:33:54 by rcabotia #+# ## ## #+# */
/* Updated: 2018/11/29 14:35:03 by rcabotia ### #+. /#+ ###.fr */
/* / */
/* / */
/* ************************************************************************** */
#include "libft.h"
int ft_getnbr(char *str)
{
size_t i;
int result;
i = 0;
result = 0;
if (str[i] == '-' || str[i] == '+')
i++;
while (str[i] >= '0' && str[i] <= '9')
result = (result * 10) + (str[i++] - '0');
if (str[0] == '-')
result *= -1;
return (result);
}