-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathft_replacestr.c
39 lines (36 loc) · 1.31 KB
/
ft_replacestr.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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_replacestr.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: dbaldy <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2016/02/13 15:07:31 by dbaldy #+# #+# */
/* Updated: 2016/02/13 15:45:11 by dbaldy ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
char *ft_replacestr(char *old, char *to_check, char *alias)
{
char *ret;
char *buf;
int i;
i = 0;
buf = NULL;
ret = ft_strdup(old);
while (old[i])
{
if (ft_strncmp(&old[i], to_check, ft_strlen(to_check)) == 0)
{
if (buf != NULL)
free(buf);
buf = ft_strsub(ret, 0, i);
free(ret);
ret = ft_strjoin_multiple(3, buf, alias,
&old[i + ft_strlen(alias)]);
}
i++;
}
free(old);
return (ret);
}