42_minishell/utils/ft_strreplace.c
2023-02-16 14:30:28 +01:00

18 lines
481 B
C

#include "utils.h"
char *ft_strreplace(const char *str, const char *fill, size_t start, size_t stop)
{
char *out;
size_t sum;
out = malloc((ft_strlen(str) + ft_strlen(fill) - (stop - start) + 1 * sizeof(char)));
if (out == NULL)
return (NULL);
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';
return (out);
}