-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathft_strmapi.c
More file actions
51 lines (47 loc) · 1.43 KB
/
ft_strmapi.c
File metadata and controls
51 lines (47 loc) · 1.43 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: sde-silv <sde-silv@student.42berlin.de> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/06/12 15:05:20 by sde-silv #+# #+# */
/* Updated: 2023/06/12 15:05:57 by sde-silv ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
/*
include ft_strlen when testing
static char ft_toupper_fd(unsigned int i, char c)
{
if ('a' <= (int)c && (int)c <= 'z')
return ((char)((int)c - 32));
else
return (c);
}
*/
char *ft_strmapi(char const *s, char (*f)(unsigned int, char))
{
unsigned int i;
char *c;
c = malloc(ft_strlen(s) + 1);
if (!c)
return (NULL);
i = 0;
while (s[i])
{
c[i] = (*f)(i, s[i]);
i ++;
}
c[i] = '\0';
return (c);
}
/*
int main(void)
{
char *ptr;
ptr = "Hello\n";
write(1,ft_strmapi(ptr, ft_toupper_fd),6);
return (0);
}
*/