> 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/c00/ft_print_numbers.md).

# ft\_print\_numbers

This exercise is very similar to the previous ones, but instead of printing the alphabet, we will print the digits from '0' to '9' in ascending order. The logic is almost the same as the previous tasks, but now we are dealing with digits instead of letters.

#### Requirements:

* **Output:** Print all digits from '0' to '9' on a single line.
* **Allowed Function:** Only `write` can be used for printing.
* **Return Type:** The function should not return anything (`void`).
* **Character Range:** We need to print digits from `'0'` to `'9'` in ascending order.

#### Plan:

* **Start with '0':** Initialize the variable `c` to the character `'0'`.
* **Increment the character:** Use a `while` loop to print each digit from '0' to '9', incrementing the character after each print.
* **Output each digit:** Use the `write` function to print each digit to the standard output.

#### Code Implementation:

```c
#include <unistd.h>  // For the write function

void ft_print_numbers(void)
{
    char c = '0';  // Start with the digit '0'

    // Loop while c is less than or equal to '9'
    while (c <= '9')
    {
        write(1, &c, 1);  // Write the current digit to standard output
        c++;  // Move to the next digit
    }
}
```

#### Explanation of the Changes:

* **Variable Initialization:**\
  The variable `c` is initialized to the character `'0'`, as we need to start printing from the digit '0' and move up to '9'.
* **While Loop:**\
  The `while` loop checks if `c` is less than or equal to `'9'`. If true, it prints the character and increments `c` to the next digit.
* **write Function:**\
  The `write` function is used to print each digit, one by one, to the standard output.

#### Example of How to Test:

Here’s a simple `main.c` to test the `ft_print_numbers` function:

```c
#include <unistd.h>

// Function prototype
void ft_print_numbers(void);

int main(void)
{
    ft_print_numbers();  // Call the function to print the digits
    return 0;
}
```

#### Expected Output:

```
0123456789
```

#### Key Points:

* **Ascending Order:** The function prints digits in ascending order from '0' to '9'.
* **System Call (`write`):** As with previous exercises, the `write` function is used to output one digit at a time.
* **While Loop:** We use a `while` loop to control the iteration through the digits from '0' to '9'.

#### Conclusion:

This exercise is similar to the previous ones, but it focuses on printing digits in ascending order. The approach is identical: we use a `while` loop to print each digit and the `write` system call to output the digits to standard output.

<mark style="color:red;">**Before submitting your project, comment out or remove your main function.**</mark>


---

# 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/c00/ft_print_numbers.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.
