> For the complete documentation index, see [llms.txt](https://42-guide.gitbook.io/42-guide/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://42-guide.gitbook.io/42-guide/piscine-life/c01/ft_putstr.md).

# ft\_putstr

**Objective:**

Create a function that displays a string of characters on the standard output.

**Turn-in Requirements:**

* **Directory**: `ex05/`
* **File**: `ft_putstr.c`
* **Allowed Functions**: `write`

**Prototype:**

```c
void ft_putstr(char *str);
```

**Implementation:**

Here’s how you can implement the function:

```c
// File: ft_putstr.c
#include <unistd.h>

void ft_putstr(char *str)
{
    int i = 0;

    while (str[i] != '\0') // Iterate through the string until the null terminator
    {
        write(1, &str[i], 1); // Write each character to standard output
        i++;
    }
}
```

**Explanation:**

1. **Input**:
   * The function takes a pointer to a character (`char *str`) representing the string to be displayed.
2. **Output**:
   * It uses the `write` system call to output characters one by one to the standard output (`1`).
3. **Loop**:
   * The loop continues until the null terminator (`'\0'`) is encountered, indicating the end of the string.

**Example Usage:**

```c
#include <unistd.h>

void ft_putstr(char *str);

int main()
{
    ft_putstr("Hello, 42!\n"); // Prints "Hello, 42!" followed by a newline
    return 0;
}
```

**Output:**

```
Hello, 42!
```

**Notes:**

* The function does not handle `NULL` strings. If you want, you can add a check to avoid passing `NULL`:

  ```c
  if (!str) return;
  ```
* This exercise helps you understand how to work with strings and interact with system-level output.


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## 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-guide.gitbook.io/42-guide/piscine-life/c01/ft_putstr.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.
