ft_strmapi.c
1 /* ************************************************************************** */ 2 /* */ 3 /* ::: :::::::: */ 4 /* ft_strmapi.c :+: :+: :+: */ 5 /* +:+ +:+ +:+ */ 6 /* By: ll-hotel <ll-hotel@student.42lyon.fr> +#+ +:+ +#+ */ 7 /* +#+#+#+#+#+ +#+ */ 8 /* Created: 2023/11/07 20:36:20 by ll-hotel #+# #+# */ 9 /* Updated: 2023/11/08 19:54:46 by ll-hotel ### ########.fr */ 10 /* */ 11 /* ************************************************************************** */ 12 13 #include <stdlib.h> 14 15 char *ft_strmapi(const char *s, char (*f)(unsigned int, char)) 16 { 17 char *p; 18 size_t i; 19 20 if (!s || !f) 21 return (0); 22 i = 0; 23 while (s[i]) 24 i++; 25 p = malloc(sizeof(char) * (i + 1)); 26 if (!p) 27 return (0); 28 i = -1; 29 while (s[++i]) 30 p[i] = (*f)(i, s[i]); 31 p[i] = 0; 32 return (p); 33 }