Archived
1
0
This repository has been archived on 2024-10-25. You can view files and clone it, but cannot push or open issues or pull requests.
so_long/libft/ft_strmapi.c

34 lines
1.2 KiB
C
Raw Normal View History

2024-01-13 19:13:17 +01:00
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strmapi.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: adjoly <adjoly@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/11/11 11:44:24 by adjoly #+# #+# */
/* Updated: 2023/11/13 16:14:32 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 || !f)
return (NULL);
res = ft_calloc((ft_strlen(s) + 1), sizeof(char));
if (res == NULL)
return (NULL);
while (s[i])
{
res[i] = f(i, s[i]);
i++;
}
res[i] = '\0';
return (res);
}