mirror of
https://github.com/Ladebeze66/libft.git
synced 2025-12-13 04:36:55 +01:00
34 lines
1.2 KiB
C
Executable File
34 lines
1.2 KiB
C
Executable File
/* ************************************************************************** */
|
|
/* */
|
|
/* ::: :::::::: */
|
|
/* ft_strmapi.c :+: :+: :+: */
|
|
/* +:+ +:+ +:+ */
|
|
/* By: fgras-ca <fgras-ca@student.42.fr> +#+ +:+ +#+ */
|
|
/* +#+#+#+#+#+ +#+ */
|
|
/* Created: 2023/02/16 13:38:52 by fgras-ca #+# #+# */
|
|
/* Updated: 2023/11/14 17:04:43 by fgras-ca ### ########.fr */
|
|
/* */
|
|
/* ************************************************************************** */
|
|
|
|
#include "libft.h"
|
|
|
|
char *ft_strmapi(const char *s, char (*f)(unsigned int, char))
|
|
{
|
|
char *result;
|
|
unsigned int i;
|
|
|
|
if (!s)
|
|
return (0);
|
|
result = malloc(sizeof(char) * (ft_strlen(s) + 1));
|
|
if (!result)
|
|
return (0);
|
|
i = 0;
|
|
while (s[i])
|
|
{
|
|
result[i] = f(i, s[i]);
|
|
i++;
|
|
}
|
|
result[i] = 0;
|
|
return (result);
|
|
}
|