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

# ft\_strupcase

**Objective:**

Create a function that transforms all lowercase letters in a string into uppercase letters. The function modifies the original string and returns it.

***

**Turn-in Requirements:**

* **Directory:** `ex07/`
* **File:** `ft_strupcase.c`
* **Allowed Functions:** None

***

**Prototype:**

```c
char *ft_strupcase(char *str);
```

***

**Implementation:**

Here’s the original implementation, followed by an optimized version:

**Code Implementation:**

```c
char *ft_strupcase(char *str)
{
    int i;

    i = 0;
    while (str[i] != '\0') // Loop through each character in the string
    {
        // If the character is a lowercase letter ('a' to 'z'), convert it to uppercase
        if (str[i] >= 'a' && str[i] <= 'z')
            str[i] -= 32; // Subtract 32 to convert lowercase to uppercase
        i++;
    }
    return (str); // Return the modified string
}
```

**Explanation:**

* **Input Parameter:**\
  The function takes a single parameter, `str`, which is a pointer to the first character of the string.
* **Conversion Logic:**
  * If a character is within the range `'a'` to `'z'`, subtracting the difference between `32`converts it to uppercase.
  * This transformation is done directly on the original string.
* **Return Value:**\
  The function returns the pointer to the modified string.

***

**Example Usage:**

```c
#include <stdio.h>

char *ft_strupcase(char *str);

int main()
{
    char str1[] = "hello world";
    char str2[] = "42Berlin";
    char str3[] = "";
    char str4[] = "AlreadyUpperCase";

    printf("%s\n", ft_strupcase(str1)); // Output: HELLO WORLD
    printf("%s\n", ft_strupcase(str2)); // Output: 42BERLIN
    printf("%s\n", ft_strupcase(str3)); // Output: (empty string)
    printf("%s\n", ft_strupcase(str4)); // Output: ALREADYUPPERCASE
    return 0;
}
```

***

**Explanation of Outputs:**

* `"hello world"`: All lowercase letters are converted to uppercase.
* `"42Berlin"`: Only the lowercase letters (`e`, `r`, `l`, `i`, `n`) are converted.
* `""`: The empty string remains unchanged.
* `"AlreadyUpperCase"`: The function leaves uppercase letters unchanged.

***

**Notes:**

* Remove or comment out the `main` function when submitting your code.
* Ensure your code adheres to the Norminette coding standards.
* This implementation is efficient, with an `O(n)` time complexity where `n` is the length of the string.


---

# 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_strupcase.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.
