简体   繁体   English

如何修复警告 C4047?

[英]How to I fix warning C4047?

I got a warning C4047: 'return': 'char' differs in levels of indirection from 'char *' from my compiler.我收到警告 C4047: 'return': 'char' 在间接级别上与我的编译器中的 'char *' 不同。 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]. char word[] 的数组编号是 25,所以 char word[25]。

Word is the pointer to char not char. Word 是指向 char 而不是 char 的指针。 Your function returns char not pointer to char.您的 function 返回 char 而不是指向 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.因为它对于初学者 C 程序员来说不太容易混淆。

If the word is the C string (null char (or another words zero ) terminated char array) it should look like this:如果这个word是 C 字符串(空字符(或另一个词零)终止的字符数组),它应该如下所示:

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

    return word;
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM