-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathft_build_nbr.c
More file actions
40 lines (37 loc) · 1.27 KB
/
ft_build_nbr.c
File metadata and controls
40 lines (37 loc) · 1.27 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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_build_nbr.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: fokrober <fokrober@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2019/04/23 05:44:19 by fokrober #+# #+# */
/* Updated: 2019/04/23 14:28:46 by fokrober ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
char *ft_build_nbr(const char *s)
{
int i;
char *result;
result = ft_strnew(0);
i = 0;
if (!s)
return ((char*)s);
if (ft_isdigit(s[i + 1]) || ft_isdigit(s[i]))
{
if (s[i] == '-')
{
result = ft_push_char(result, s[i]);
i++;
}
else if (s[i] == '+')
i++;
while (ft_isdigit(s[i]))
{
result = ft_push_char(result, s[i]);
i++;
}
}
return (result);
}