-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathft_strntrim.c
More file actions
36 lines (33 loc) · 1.19 KB
/
ft_strntrim.c
File metadata and controls
36 lines (33 loc) · 1.19 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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strntrim.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: sconstab <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2019/05/31 13:55:30 by sconstab #+# #+# */
/* Updated: 2019/06/06 14:00:44 by sconstab ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
char *ft_strntrim(char const *s, char c)
{
size_t i;
size_t j;
size_t it;
char *ns;
i = 0;
j = 0;
it = ft_strlen(s) - 1;
ns = ft_strnew(it + 1);
if (s == NULL)
return (NULL);
while (s[i] == c)
i++;
while (s[it] == c)
it--;
it++;
while (i < it && s[i])
ns[j++] = s[i++];
return (ns);
}