警告C4047:'=':'char'的间接级别与'char [2]'不同

问题描述 投票:-1回答:2

每当我编译程序时,我都会收到一个错误:警告C4047。我对使用这种语言进行编程非常陌生,并且不了解问题是什么或如何修复它。非常感谢任何帮助,谢谢。

错误特别在线word[x - 1] = "i";

void RuleOne(char word[], char plural[]) {

    int x = strlen(word);

    word[x - 1] = "i";

    plural = strcat(word, "es");

}
c
2个回答
6
投票
word[x - 1] = "i";

"i"是一个字符串文字,而不是字符常量。

如果需要字符,请使用单引号:

words[x - 1] = 'i';
               ^ ^

此外,你对plural做错了。这是一个错误的工作:

plural = strcat(word, "es");

你实际上是将"es"附加到word并让指针plural指向与word相同的地址,这显然不是你想要做的。尝试复制word追加es到副本:

strcpy(plural, word);
strcat(plural, "es");

由于strcpy()返回复制的字符串(缓冲区),您可以将其放在strcat()中:

strcat(strcpy(plural, word), "es");

虽然,我建议你不要在完全理解它是如何工作之前这样做。


0
投票

您的代码中存在两个问题

1)确实如iBug所述

words[x - 1] = 'i'; // not "i"

2)plural未设置为复数版本

// instead of >> plural = strcat(word, "es");
strcpy(plural, word);
strcat(plural, "es");

是你想要的。

© www.soinside.com 2019 - 2024. All rights reserved.