每当我编译程序时,我都会收到一个错误:警告C4047。我对使用这种语言进行编程非常陌生,并且不了解问题是什么或如何修复它。非常感谢任何帮助,谢谢。
错误特别在线word[x - 1] = "i";
void RuleOne(char word[], char plural[]) {
int x = strlen(word);
word[x - 1] = "i";
plural = strcat(word, "es");
}
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");
虽然,我建议你不要在完全理解它是如何工作之前这样做。
您的代码中存在两个问题
1)确实如iBug所述
words[x - 1] = 'i'; // not "i"
2)plural
未设置为复数版本
// instead of >> plural = strcat(word, "es");
strcpy(plural, word);
strcat(plural, "es");
是你想要的。