strmapi done && split fix
This commit is contained in:
31
ft_strmapi.c
Normal file
31
ft_strmapi.c
Normal file
@ -0,0 +1,31 @@
|
|||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* ft_strmapi.c :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: adjoly <adjoly@student.42.fr> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2023/11/11 11:44:24 by adjoly #+# #+# */
|
||||||
|
/* Updated: 2023/11/11 11:50:17 by adjoly ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
#include "libft.h"
|
||||||
|
|
||||||
|
char *ft_strmapi(char const *s, char (*f)(unsigned int, char))
|
||||||
|
{
|
||||||
|
int i;
|
||||||
|
char *res;
|
||||||
|
|
||||||
|
i = 0;
|
||||||
|
if (s == NULL)
|
||||||
|
return (NULL);
|
||||||
|
res = malloc((ft_strlen(s) + 1) * sizeof(char));
|
||||||
|
while (s[i])
|
||||||
|
{
|
||||||
|
res[i] = f(i, s[i]);
|
||||||
|
i++;
|
||||||
|
}
|
||||||
|
res[i] = '\0';
|
||||||
|
return (res);
|
||||||
|
}
|
Reference in New Issue
Block a user