-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathft_strmapi.c
More file actions
51 lines (46 loc) · 1.47 KB
/
ft_strmapi.c
File metadata and controls
51 lines (46 loc) · 1.47 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
45
46
47
48
49
50
51
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strmapi.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: thlibers <thlibers@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2025/10/17 11:16:32 by thlibers #+# #+# */
/* Updated: 2025/10/17 12:29:54 by thlibers ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
char *ft_strmapi(char const *s, char (*f)(unsigned int, char))
{
char *mapi;
unsigned int i;
i = 0;
if (s == NULL || f == NULL)
return (NULL);
mapi = malloc(sizeof(char) * (ft_strlen(s) + 1));
if (mapi == NULL)
return (NULL);
while (s[i])
{
mapi[i] = f(i, s[i]);
i++;
}
mapi[i] = '\0';
return (mapi);
}
// char f(unsigned int n, char c)
// {
// n = 0;
// if (c >= 'a' && c <= 'z')
// c -= 32;
// return (c);
// }
// int main()
// {
// char *mapi;
// char s[] = "salut";
// mapi = ft_strmapi(s, f);
// printf ("%s", mapi);
// free(mapi);
// return (0);
// }