Turning a string all to lowercase problems

I can make a single char go from lowercase to uppercase, or vice versa. But what I'm trying to accomplish now is trying to turn a whole string. What I thought I would do was take the string as a char array[100 and process each letter with my method of turning a single char to uppercase or lowercase. I figured it was a lot harder/complicated than I thought.

Here's my attempt -

My FAILED attempt at creating a string case changer
1
2
3
4
5
6
7
inline void STRING_TOLOWER (char letters[100])
{
    for (int i = 0; i <= letters[100]; i++)
    {
        letters[i] = CHAR_TOLOWER(letters[i]);
    }
}


My WORKING attempt for changing a letter case changer
1
2
3
4
5
6
7
inline void CHAR_TOLOWER (char letter)
{
    for (int i = letter + 0; i < 65 && i < 91; i - 32)
    {
        CHAR_TOLOWER(letter);
    }
}


Any help or suggestions would be nice. Thanks
1
2
3
4
5
6
7
inline void STRING_TOLOWER (char letters[100])
{
    for (int i = 0; i <= 100; i++)//notice that you need the size
    {
        letters[i] = CHAR_TOLOWER(letters[i]);
    }
}

Whithout knowing the size:
1
2
3
4
5
6
7
8
9
void STRING_TOLOWER (char* letters)
{
    int i = 0;
    while(true)
    {
        if ( letters[i] == '\0' ) break;
        letters[i] = CHAR_TOLOWER(letters[i++]);
    }
}
Thanks! I'm very confused about pointers at the moment, so I don't really get all that pointer works.
Also...for (int i = 0; i <= 100; i++) will get you out of bounds of the array anyway, you need i <= 99 or i < 100.

Also, there is a function called tolower() that will do your CHAR_TOLOWER() for you.

For checking the length of the the char*, you can also use strlen(), rather then manually checking for a \0. Then just use a normal for loop.
I've always liked to do
for (;*letters;letters++)
You can't get it faster than that.
Topic archived. No new replies allowed.