42_minishell/utils/ft_strreplace.c
Etienne Rey-bethbeder b20d4e0ddc bozo
2023-02-14 13:55:02 +01:00

25 lines
639 B
C

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