How to I fix warning C4047?

709 views Asked by At

I got a warning C4047: 'return': 'char' differs in levels of indirection from 'char *' from my compiler. I'm new to coding and don't understand how to fix this problem.

My code is:

char upperToLower(char word[])
{

    int i;
    for (i = 0; i < 25; i++)
    {
        word[i] = tolower(word[i]);
    }

    return word;
}

Can anyone help me with the code?

the array number for char word[] is 25, so char word[25].

1

There are 1 answers

2
0___________ On

Word is the pointer to char not char. Your function returns char not pointer to char.

It should be:

char *upperToLower(char word[])

And I personally prefer

char *upperToLower(char *word)

as it is less confusing for the beginner C programmers.

If the word is the C string (null char (or another words zero ) terminated char array) it should look like this:

char *upperToLower(char *word)
{
    char *wrk = word;
    while(*wrk)
    {
        *wrk = tolower((unsigned char)*wrk);
        wrk++;
    }

    return word;
}