# ft\_striteri

### Subject

{% code overflow="wrap" %}

```
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.
```

{% endcode %}

### 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

<details>

<summary>ft_striteri</summary>

{% code title="ft\_striteri.c" overflow="wrap" lineNumbers="true" %}

```c
#include "libft.h"

void ft_striteri(char *s, void (*f)(unsigned int, char*))
{
    unsigned int i;
    
    i = 0;
    /* looping over the whole original string */
    while (s[i])
    {
        /* apply the function f to the character at index i
         * passing i and the address to s[i] as parameter to f
         * f will update the original string directly
         */
        (*f)(i, &s[i]);
        i++;
    }
}
```

{% endcode %}

</details>


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://42-cursus.gitbook.io/guide/0-rank-00/libft/additional-functions/ft_striteri.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
