【发布时间】:2017-04-22 17:55:02
【问题描述】:
我正在制作一个将单数名词转换为复数名词的程序。我对编码非常陌生,并且在代码的第 44 行不断收到错误消息,即我进行了“从 'char' 到 'char* 的无效转换”。此外,在第 41 行,我得到“从 'char' 到 'const char* 的无效转换”。我不完全确定这意味着什么或如何解决?我正在使用带有 C++ 的 NetBeans,这里是代码:
#include <stdio.h>
#include <string.h>
#define max_word 20
void pluralize (char word[]);
int main (void)
{
char noun[max_word]; /* stores temporary word entered by user */
printf("Enter a noun in singular form: ");
scanf("%s", noun);
while (strcmp(noun, "done") != 0)
{
pluralize (noun);
printf("The plural form is %s\n", noun);
}
}
void pluralize (char word[])
{
int length;
char noun;
length=1;
length = strlen(word);
for (;;)
{
printf("Enter a noun in singular form: ");
scanf("%s", noun);
if ((strcmp( noun, "done") == 0))
break;
pluralize (noun);
printf("The plural form is %s\n", noun);
}
return;
}
【问题讨论】:
-
这不是 C++,而是 C。请相应地标记您的问题。
-
@DanielKamilKozar 糟糕,我刚刚删除了 C 标记,因为“我正在使用带有 C++ 的 NetBeans”。对我来说,这看起来像是有效的 C++。
-
那么,我们应该如何知道第 44 行是什么?您希望我们数行吗?
-
char noun[max_word];在一个函数中与char noun;在另一个函数中。找出差异。 -
@Etienne OP 明确指出这是一个 C++ 程序,无论成语如何。请不要接受错误的编辑。谢谢。