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

# ft\_print\_alphabet

#### Objective:

The goal of this exercise is to write a function named `ft_print_alphabet` that prints the lowercase alphabet in ascending order, starting from 'a', all on a single line. We are allowed to use only the `write` function for output. The function should not return anything (its return type is `void`).

#### Function Prototype:

```c
void ft_print_alphabet(void);
```

#### Requirements:

* **Output:** Print all lowercase letters of the alphabet from 'a' to 'z' without spaces.
* **Allowed Function:** You can only use `write` for printing, which is part of the standard library in C.
* **Return Type:** The function should not return anything (`void`).
* **Character Range:** Ensure the function prints only lowercase letters from 'a' to 'z' in the correct order.

Steps&#x20;

1. **ASCII Values of Characters:**
   * Each character in the alphabet has an associated ASCII value.
   * The ASCII value of 'a' is 97, and the ASCII value of 'z' is 122.
   * You can use a loop to iterate from 'a' to 'z', printing each character.
2. **Solution Approach:**
   * Use a `while` loop to iterate from the ASCII value of 'a' to 'z'.
   * For each character, use `write` to print it to the standard output.

#### Code Implementation:

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

void ft_print_alphabet(void)
{
    char c = 'a';  // Start with the letter 'a'

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

```

#### Explanation:

* **Header File:**\
  The code includes the `<unistd.h>` header, which is necessary for using the `write` function.
* **Loop:**\
  The loop starts from the character 'a' and continues until the character 'z'. Each character is printed using the `write` function.
* **write Function:**\
  The `write` function takes three parameters:
  1. `1`: The file descriptor for standard output (stdout).
  2. `&c`: A pointer to the character to be printed.
  3. `1`: The number of bytes to write (since we're printing one character at a time, this is `1`).

#### How to Test:

To test the function, you can write a simple main program that calls `ft_print_alphabet`.

Example `main.c`:

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

// Function prototype
void ft_print_alphabet(void);

int main(void)
{
    ft_print_alphabet();  // This will print the alphabet
    return 0;
}
```

#### Expected Output:

```
abcdefghijklmnopqrstuvwxyz
```

#### Key Points:

* **Efficiency:** The function uses a loop to print each character one at a time, which is a straightforward approach.
* **System Call:** By using `write`, we bypass the usual C library's `printf` function and directly interact with the operating system to output data.

#### Conclusion:

This exercise helps in understanding how to manipulate basic I/O operations in C and reinforces the use of system calls. It also helps in familiarizing yourself with loops, character handling, and system-level 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_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.
