-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathft_striter.c
74 lines (70 loc) · 1.97 KB
/
ft_striter.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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_striter.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: mbutt <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2019/03/10 15:50:03 by mbutt #+# #+# */
/* Updated: 2019/03/26 18:29:29 by mbutt ### ########.fr */
/* */
/* ************************************************************************** */
/*
** Applies the function f to each character of the string passed as argument.
** Each character is passed by address to f to be modified if necessary.
** Param # 1 - The string to iterate
** Param # 2 - The function to apply to each character of s.
** Return VALUE - None
** Libc functions - None.
*/
#include "libft.h"
void ft_striter(char *s, void (*f)(char *))
{
unsigned int i;
i = 0;
if (!s)
return ;
if (s && f)
while (s[i])
{
f(s + i);
i++;
}
}
/*
**Different ways to write the while loop
** By using a pointer
** while(*s)
** {
** f(&*s);
** s++;
** f(&*s++);// above two lines can be replaced by this one line.
** }
** By using an index
** while (s[i])
** {
** f(&s[i]);
** i++;
** f(&s[i++]);// above two lines can be replaced by this one line.
** }
** By using an index
** while (s[i])
** {
** f(s + i);
** i++;
** f(s+(i++));// above two lines can be replaced by this one line.
** }
*/
/*
**void f_striter(char *s)
** {
** *s = 'F';
** }
**int main (void)
**{
** char string1[] = "THIS IS A TEST";
** ft_striter(string1, f_striter);
** printf("%s", string1);
** return(0);
**}
*/