-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathft_ireplace_str.c
33 lines (30 loc) · 1.31 KB
/
ft_ireplace_str.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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_replace_str.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: dbaldy <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2016/02/15 15:57:00 by dbaldy #+# #+# */
/* Updated: 2016/04/29 13:58:05 by dbaldy ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
#include <stdlib.h>
char *ft_ireplace_str(char *old, char *replace, int i, int length)
{
char *new;
char *buf;
char *end;
if ((int)ft_strlen(old) < i)
return (old);
buf = ft_strsub(old, 0, i);
if ((int)ft_strlen(old) >= i + length)
end = ft_strsub(old, i + length, ft_strlen(old) - i - length);
else
end = ft_strdup("");
new = ft_strjoin_multiple(3, buf, replace, end);
free(buf);
free(end);
return (new);
}