minishell
ft_strmapi.c
Go to the documentation of this file.
1 /* ************************************************************************** */
2 /* */
3 /* ::: :::::::: */
4 /* ft_strmapi.c :+: :+: :+: */
5 /* +:+ +:+ +:+ */
6 /* By: kfujita <kfujita@student.42tokyo.jp> +#+ +:+ +#+ */
7 /* +#+#+#+#+#+ +#+ */
8 /* Created: 2022/04/19 07:47:01 by kfujita #+# #+# */
9 /* Updated: 2022/04/25 23:29:21 by kfujita ### ########.fr */
10 /* */
11 /* ************************************************************************** */
12 
13 #include "ft_string.h"
14 
15 char *ft_strmapi(char const *s, char (*f)(unsigned int, char))
16 {
17  char *p_ret;
18  size_t index;
19 
20  if (s == NULL || *s == '\0')
21  return (ft_strdup(""));
22  p_ret = ft_strdup(s);
23  if (f == NULL || p_ret == NULL)
24  return (p_ret);
25  index = 0;
26  while (*s != '\0')
27  {
28  p_ret[index] = f(index, *s++);
29  index++;
30  }
31  return (p_ret);
32 }
char * ft_strdup(const char *s1)
Definition: ft_strdup.c:16
char * ft_strmapi(char const *s, char(*f)(unsigned int, char))
Definition: ft_strmapi.c:15