-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathft_strmapi.c
More file actions
44 lines (40 loc) · 1.35 KB
/
ft_strmapi.c
File metadata and controls
44 lines (40 loc) · 1.35 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strmapi.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: simarcha <simarcha@student.42barcel> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/01/20 12:25:28 by simarcha #+# #+# */
/* Updated: 2024/01/20 15:46:39 by simarcha ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
char *ft_strmapi(char const *s, char (*f)(unsigned int, char))
{
char *str;
unsigned int i;
i = -1;
str = malloc(sizeof(char) * (ft_strlen(s) + 1));
if (!str)
return (NULL);
while (s[++i] != '\0')
str[i] = (*f)(i, s[i]);
str[i] = 0;
return (str);
}
/*
#include <stdio.h>
char f(unsigned int i, char c)
{
char str;
str = c + i;
return (str);
}
int main()
{
char str1[] = "abc";
char* str2;
str2 = ft_strmapi(str1, *f);
printf("%s\n", str2);
}*/