35 lines
1.2 KiB
C
35 lines
1.2 KiB
C
/* ************************************************************************** */
|
|
/* */
|
|
/* ::: o_ :::::: ::: */
|
|
/* ft_strmapi.c :+: / :+::+: :+: */
|
|
/* +:+ > +:++:+ +:+ */
|
|
/* By: whaffman <whaffman@student.codam.nl> +#+ +:+ +#++#++:++#++ */
|
|
/* +#+ +#+#+ +#++#+ +#+ \o/ */
|
|
/* Created: 2024/10/10 17:00:30 by whaffman #+#+# #+#+# #+# #+# | */
|
|
/* Updated: 2024/10/10 17:00:30 by whaffman ### ### ### ### / \ */
|
|
/* */
|
|
/* ************************************************************************** */
|
|
|
|
#include <stdlib.h>
|
|
#include "libft.h"
|
|
|
|
char *ft_strmapi(char const *s, char (*f)(unsigned int, char))
|
|
{
|
|
int i;
|
|
char *result;
|
|
|
|
if (!s)
|
|
return (NULL);
|
|
result = malloc((ft_strlen(s) + 1) * sizeof(char));
|
|
if (!result)
|
|
return (NULL);
|
|
i = 0;
|
|
while (s[i])
|
|
{
|
|
result[i] = f(i, s[i]);
|
|
i++;
|
|
}
|
|
result[i] = '\0';
|
|
return (result);
|
|
}
|