> 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/c02/ft_str_is_alpha.md).

# ft\_str\_is\_alpha

**Objective:**

Create a function that checks whether a string contains only alphabetic characters (uppercase or lowercase). The function should return `1` if the string contains only alphabetic characters (or is empty) and `0` otherwise.

***

**Turn-in Requirements:**

* **Directory:** `ex02/`
* **File:** `ft_str_is_alpha.c`
* **Allowed Functions:** None

***

**Prototype:**

```c
int ft_str_is_alpha(char *str);
```

***

**Implementation:**

Here’s how you can implement the function:

```c
// File: ft_str_is_alpha.c

int ft_str_is_alpha(char *str)
{
    int i;

    i = 0;
    while (str[i] != '\0') // Loop through each character of the string
    {
        // Check if the character is not within 'a'-'z' or 'A'-'Z'
        if (!((str[i] >= 'a' && str[i] <= 'z') || (str[i] >= 'A' && str[i] <= 'Z')))
            return (0); // Return 0 if a non-alphabetic character is found
        i++;
    }
    return (1); // Return 1 if all characters are alphabetic or the string is empty
}
```

***

**Explanation:**

* **Input Parameter:**\
  The function takes a single parameter, `str`, which is a pointer to the first character of the input string.
* **Loop through the string:**\
  The `while` loop continues until the null terminator (`\0`) is reached, indicating the end of the string.
* **Check each character:**
  * The condition checks if the current character is **not** within the ranges `'a'` to `'z'` or `'A'` to `'Z'`.
  * If any character falls outside these ranges, the function immediately returns `0`.
* **Empty string:**\
  If the string is empty (i.e., `str[0] == '\0'`), the loop doesn’t execute, and the function returns `1` as required.

***

**Example Usage:**

```c
#include <stdio.h>

int ft_str_is_alpha(char *str);

int main()
{
    printf("%d\n", ft_str_is_alpha("Hello"));        // Output: 1
    printf("%d\n", ft_str_is_alpha("Hello123"));    // Output: 0
    printf("%d\n", ft_str_is_alpha(""));            // Output: 1
    printf("%d\n", ft_str_is_alpha("42Berlin"));    // Output: 0
    return 0;
}
```

* **Explanation of Outputs:**
  * `"Hello"`: All alphabetic characters → returns `1`.
  * `"Hello123"`: Contains non-alphabetic characters → returns `0`.
  * `""`: Empty string → returns `1`.
  * `"42Berlin"`: Contains numeric characters → returns `0`.

***

**Notes:**

* Remove or comment out the `main` function when submitting your code.
* Make sure your code adheres to the Norminette coding standards.
* Avoid including unnecessary files in your directory.


---

# 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/c02/ft_str_is_alpha.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.
