2023-02-21 08:35:08 -05:00
|
|
|
/* ************************************************************************** */
|
|
|
|
/* */
|
|
|
|
/* ::: :::::::: */
|
|
|
|
/* ft_strreplace.c :+: :+: :+: */
|
|
|
|
/* +:+ +:+ +:+ */
|
|
|
|
/* By: cchauvet <cchauvet@student.42angoulem +#+ +:+ +#+ */
|
|
|
|
/* +#+#+#+#+#+ +#+ */
|
|
|
|
/* Created: 2023/02/21 12:46:20 by cchauvet #+# #+# */
|
|
|
|
/* Updated: 2023/02/21 12:58:44 by cchauvet ### ########.fr */
|
|
|
|
/* */
|
|
|
|
/* ************************************************************************** */
|
|
|
|
|
2023-02-01 11:28:38 -05:00
|
|
|
#include "utils.h"
|
|
|
|
|
2023-02-21 08:35:08 -05:00
|
|
|
char *ft_strreplace(const char *str, const char *fill,
|
|
|
|
size_t start, size_t stop)
|
2023-02-01 11:28:38 -05:00
|
|
|
{
|
|
|
|
char *out;
|
|
|
|
size_t sum;
|
|
|
|
|
2023-02-21 08:35:08 -05:00
|
|
|
out = malloc((ft_strlen(str) + ft_strlen(fill) -\
|
|
|
|
(stop - start) + 1 * sizeof(char)));
|
2023-02-01 11:28:38 -05:00
|
|
|
if (out == NULL)
|
2023-02-16 08:30:28 -05:00
|
|
|
return (NULL);
|
2023-02-01 11:28:38 -05:00
|
|
|
ft_strncpy(out, str, start);
|
|
|
|
ft_strncpy(out + start, fill, ft_strlen(fill));
|
|
|
|
sum = start + ft_strlen(fill);
|
|
|
|
ft_strncpy(out + sum, str + stop, ft_strlen(str) - stop);
|
|
|
|
out[sum + ft_strlen(str) - stop] = '\0';
|
2023-02-16 08:30:28 -05:00
|
|
|
return (out);
|
2023-02-01 11:28:38 -05:00
|
|
|
}
|