-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathft_striteri.c
56 lines (47 loc) · 1.62 KB
/
ft_striteri.c
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
52
53
54
55
56
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_striteri.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: edetoh <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/10/19 15:34:49 by edetoh #+# #+# */
/* Updated: 2024/10/25 11:17:32 by edetoh ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
/*
* ft_striteri applies a function to each character.
* Takes 's' (source string) and 'f' (function to apply).
* Returns nothing. Modifies the source string.
*/
void ft_striteri(char *s, void (*f)(unsigned int, char*))
{
int str_len;
int i;
str_len = ft_strlen(s);
i = 0;
while (i < str_len)
{
f(i, &s[i]);
i++;
}
}
// void i_love_alphabet(unsigned int index, char *c)
// {
// int i;
// i = index % 26;
// *c = 'a' + i;
// }
// #include <string.h>
// #include <stdio.h>
// #include <unistd.h>
// int main(void)
// {
// char str[] = "Hello, World!";
// printf("BEFORE : %s\n", str);
// ft_striteri(str, i_love_alphabet);
// printf(" AFTER : %s\n", str);
// printf("==================\n");
// return (1);
// }