ft_striteri
Subject
FT_STRITERI (simplified)
NAME
ft_striteri -- apply a function to each character of a string (index specified)
SYNOPSIS
void ft_striteri(char *s, void (*f)(unsigned int, char*));
DESCRIPTION
Apply the function 'f' to each characters of the string 's', passing its index as a first parameter.
Each character is transmitted by address to 'f' so it can be modified if necessary.
Understandable explanation
ft_striteri
works the same way as ft_strmapi
does, take a look at the explanation for ft_strmapi
and then come back here.
The difference between ft_striteri
and ft_strmapi
is that ft_striteri
doesn't return anything and works directly on the original string.
Hints
This functions takes two parameters, the first one is a string, and the second one is a function.
What ft_striteri
does is apply the function f
to every character of the string s
.
It passes the index of the character in the string, and a pointer to the character to the function f
.
The function f
directly modifies the value of the character in the original string.
At the end, we don't need to return anything but the original string will have been modified.
Commented solution
Last updated
Was this helpful?