#include <stdio.h>
void ft_striteri(char *s, void (*f)(unsigned int, char *))
{
unsigned int i;
if (!s || !f)
return ;
i = 0;
while (s[i])
{
f(i, s + i);
i++;
}
}
void test(unsigned int i, char *str)
{
printf("My inner function: index = %d and %s\n", i, str);
}
int main()
{
char *str = "Hello 42KL";
ft_striteri(str,test);
printf("test: %s\n", str);
return 0;
}
My inner function: index = 0 and Hello 42KL
My inner function: index = 1 and ello 42KL
My inner function: index = 2 and llo 42KL
My inner function: index = 3 and lo 42KL
My inner function: index = 4 and o 42KL
My inner function: index = 5 and 42KL
My inner function: index = 6 and 42KL
My inner function: index = 7 and 2KL
My inner function: index = 8 and KL
My inner function: index = 9 and L
test: Hello 42KL