38 lines
1.2 KiB
C
38 lines
1.2 KiB
C
/* ************************************************************************** */
|
|
/* */
|
|
/* ::: :::::::: */
|
|
/* ft_straddchar.c :+: :+: :+: */
|
|
/* +:+ +:+ +:+ */
|
|
/* By: lfirmin <lfirmin@student.42.fr> +#+ +:+ +#+ */
|
|
/* +#+#+#+#+#+ +#+ */
|
|
/* Created: 2024/11/08 06:02:17 by lfirmin #+# #+# */
|
|
/* Updated: 2024/11/08 06:02:17 by lfirmin ### ########.fr */
|
|
/* */
|
|
/* ************************************************************************** */
|
|
|
|
#include "libft.h"
|
|
|
|
char *ft_straddchar(char *str, char c)
|
|
{
|
|
int i;
|
|
char *res;
|
|
|
|
if (!str)
|
|
return (NULL);
|
|
i = 0;
|
|
while (str[i])
|
|
i++;
|
|
res = (char *)malloc(sizeof(char) * (i + 2));
|
|
if (!res)
|
|
return (NULL);
|
|
i = 0;
|
|
while (str[i])
|
|
{
|
|
res[i] = str[i];
|
|
i++;
|
|
}
|
|
res[i] = c;
|
|
res[i + 1] = '\0';
|
|
return (res);
|
|
}
|