> 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_reverse_alphabet.md).

# ft\_print\_reverse\_alphabet

This exercise is very similar to the previous one, with the key difference being that we need to print the alphabet in **reverse order** (from 'z' to 'a') rather than in ascending order. The only change is in how we handle the loop and the starting point of the character.

#### Requirements:

* **Output:** Print all lowercase letters of the alphabet from 'z' to 'a' in descending order, on a single line.
* **Allowed Function:** Only `write` can be used for printing.
* **Return Type:** The function should not return anything (`void`).
* **Character Range:** Ensure the function prints only lowercase letters in reverse order from 'z' to 'a'.

#### Plan:

* **Start with 'z':** Initialize the character `c` to 'z'.
* **Decrement the character:** Use a `while` loop to print each character in reverse order, i.e., decrement the character until it reaches 'a'.
* **Output each character:** Use the `write` function to print each character to the standard output.

#### Code Implementation:

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

void ft_print_reverse_alphabet(void)
{
    char c = 'z';  // Start with the letter 'z'

    // Loop while c is greater than or equal to 'a'
    while (c >= 'a')
    {
        write(1, &c, 1);  // Write the current character to standard output
        c--;  // Move to the previous character in the alphabet
    }
}
```

#### Explanation of the Changes:

* **Variable Initialization:**\
  The variable `c` is now initialized to the character `'z'`, as we need to start from 'z' and print in reverse order.
* **While Loop:**\
  The `while` loop condition checks if `c` is greater than or equal to 'a'. If true, it continues to execute, printing the character and then decrementing `c` to the previous letter in the alphabet.
* **write Function:**\
  The `write` function remains the same as in the previous exercise. It writes one character at a time to the standard output.

#### Example of How to Test:

Here’s a simple `main.c` that tests the `ft_print_reverse_alphabet` function:

```c
cKopieren#include <unistd.h>

// Function prototype
void ft_print_reverse_alphabet(void);

int main(void)
{
    ft_print_reverse_alphabet();  // Call the function to print the reverse alphabet
    return 0;
}
```

#### Expected Output:

```
zyxwvutsrqponmlkjihgfedcba
```

#### Key Points:

* **Descending Order:** The loop runs in reverse by decrementing `c` after each character is printed, starting from `'z'` and stopping at `'a'`.
* **System Call (`write`):** We continue using the `write` system call to print each character one at a time.
* **While Loop:** As with the previous task, we use a `while` loop to control the printing flow.

#### Conclusion:

This exercise is nearly identical to the previous one, with the only difference being the reverse order of the alphabet. The function efficiently prints the alphabet in reverse using a `while` loop and the `write` system call.

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