-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathft_striteri.c
53 lines (47 loc) · 1.84 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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_striteri.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: fyang <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/06/25 18:36:46 by fyang #+# #+# */
/* Updated: 2024/06/25 18:38:42 by fyang ### ########.fr */
/* */
/* ************************************************************************** */
/*PROTOTYPE
void ft_striteri(char *s, void (*f)(unsigned int, char*));
INPUT
function takes 2 parameters
1 - s POINTER TO MEMORY BLOCK containing string on which to iterate
2 - f POINTER TO FUNCTION to apply to each char, that takes 2 arguments
- unsigned int :index of char in the str
- char* :pointer to char allowing the function to modify the char
OUTPUT
-no return value
PSEUDOCODE
//check for null pointers
1 IF s is NULL OR f is NULL
return
1 ENDIF
declare, initialize an index variable i
1 WHILE character at s[index] is not the null terminator:
Call function f, passing index and address of s[index] as arguments
//f can modify the character directly since it receives a pointer
Increment index
1 EndWhile
EndProcedure
*/
#include "libft.h"
void ft_striteri(char *s, void (*f)(unsigned int, char*))
{
unsigned int i;
if (s == NULL || f == NULL)
return ;
i = 0;
while (s[i] != '\0')
{
f(i, &s[i]);
i++;
}
}