-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathft_striteri.c
More file actions
44 lines (35 loc) · 766 Bytes
/
Copy pathft_striteri.c
File metadata and controls
44 lines (35 loc) · 766 Bytes
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
/*
Works like ft_strmapi() with the difference that ft_striteri() applies function
f directly on the original string.
Passing the address (a pointer) as to modify the actual memory location of the
index / char.
*/
#include "libft.h"
void ft_striteri(char *s, void (*f)(unsigned int, char*))
{
unsigned int i;
if (!s || !(*s) || !f)
return ;
i = 0;
while (s[i])
{
f(i, &s[i]);
i++;
}
}
/*
#include <stdio.h>
void ft_wrapper(unsigned int index, char *c)
{
(void)index;
*c = (ft_toupper(*c));
}
int main(void)
{
char test_str[] = "A test string to be modified by ft_strmapi()";
printf("String before ft_strmapi(): '%s'\n", test_str);
ft_striteri(test_str, ft_wrapper);
printf("String after ft_strmapi(): '%s'\n", test_str);
return (0);
}
*/