mirror of
https://github.com/KeyZox71/ft_minipowershell.git
synced 2025-03-15 19:36:50 +01:00
34 lines
1.2 KiB
C
34 lines
1.2 KiB
C
|
/* ************************************************************************** */
|
||
|
/* */
|
||
|
/* ::: :::::::: */
|
||
|
/* ft_strmapi.c :+: :+: :+: */
|
||
|
/* +:+ +:+ +:+ */
|
||
|
/* By: adjoly <adjoly@student.42angouleme.fr> +#+ +:+ +#+ */
|
||
|
/* +#+#+#+#+#+ +#+ */
|
||
|
/* Created: 2023/11/11 11:44:24 by adjoly #+# #+# */
|
||
|
/* Updated: 2024/02/04 14:48:02 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);
|
||
|
}
|