libft
Loading...
Searching...
No Matches
ft_strmapi.c
Go to the documentation of this file.
1/* ************************************************************************** */
2/* */
3/* ::: :::::::: */
4/* ft_strmapi.c :+: :+: :+: */
5/* +:+ +:+ +:+ */
6/* By: tspoof <tspoof@student.hive.fi> +#+ +:+ +#+ */
7/* +#+#+#+#+#+ +#+ */
8/* Created: 2022/11/05 23:18:45 by tspoof #+# #+# */
9/* Updated: 2022/11/09 18:58:27 by tspoof ### ########.fr */
10/* */
11/* ************************************************************************** */
12
13#include "libft.h"
14
15char *ft_strmapi(char const *s, char (*f)(unsigned int, char))
16{
17 int i;
18 size_t s_len;
19 char *str;
20
21 if (!s || !f)
22 return (NULL);
23 s_len = ft_strlen(s);
24 str = (char *)malloc(sizeof(char) + (s_len));
25 if (!str)
26 return (NULL);
27 i = 0;
28 while (s[i])
29 {
30 str[i] = f(i, s[i]);
31 i++;
32 }
33 str[i] = '\0';
34 return (str);
35}
char * ft_strmapi(char const *s, char(*f)(unsigned int, char))
Create a copy of a string passing each char through a function.
Definition ft_strmapi.c:15
size_t ft_strlen(const char *s)
Length of the string.
Definition ft_strlen.c:15
float f
Definition unity.c:1777