tgrekov-libft
HIVE libft Oct 2023
Loading...
Searching...
No Matches
ft_strmapi.c
Go to the documentation of this file.
1/* ************************************************************************** */
2/* */
3/* ::: :::::::: */
4/* ft_strmapi.c :+: :+: :+: */
5/* +:+ +:+ +:+ */
6/* By: tgrekov <tgrekov@student.hive.fi> +#+ +:+ +#+ */
7/* +#+#+#+#+#+ +#+ */
8/* Created: 2023/10/27 23:54:37 by tgrekov #+# #+# */
9/* Updated: 2023/11/09 20:12:09 by tgrekov ### ########.fr */
10/* */
11/* ************************************************************************** */
12
20#include "libft.h"
21
34char *ft_strmapi(char const *s, char (*f)(unsigned int, char))
35{
36 unsigned int len;
37 char *s2;
38
39 if (!s)
40 return (0);
41 len = ft_strlen(s);
42 s2 = ft_calloc(len + 1, 1);
43 if (!s2)
44 return (0);
45 while (len--)
46 s2[len] = f(len, s[len]);
47 return (s2);
48}
void * ft_calloc(size_t count, size_t size)
Allocates count * size bytes with malloc and returns a pointer to the result.
Definition ft_calloc.c:34
size_t ft_strlen(const char *str)
Get length of str.
Definition ft_strlen.c:28
char * ft_strmapi(char const *s, char(*f)(unsigned int, char))
Allocates and creates a new string from the output of function f processing each character of string ...
Definition ft_strmapi.c:34