Reputation: 99
Whenever I compile my program I get one error: warning C4047. I'm very new to programming in this language and don't understand what the problem is or how to fix it. Any help would be greatly appreciated thank you.
The error is specifically on line word[x - 1] = "i";
void RuleOne(char word[], char plural[]) {
int x = strlen(word);
word[x - 1] = "i";
plural = strcat(word, "es");
}
Upvotes: 1
Views: 4446
Reputation: 37227
word[x - 1] = "i";
"i"
is a string literal, not a character constant.
Use single quotes if you want characters:
words[x - 1] = 'i';
^ ^
Besides, you're doing it wrong with plural
. This is a wrong job:
plural = strcat(word, "es");
You're actually appending "es"
to word
and let the pointer plural
point to the same address as word
, which is obviously not what you intended to do. Try copying word
the append es
to the replica:
strcpy(plural, word);
strcat(plural, "es");
Since strcpy()
returns the copied string (buffer), you can put it inside strcat()
:
strcat(strcpy(plural, word), "es");
Though, I recommend not doing so before you fully understand how it works.
Upvotes: 6
Reputation: 28830
There are two problems in your code
1) Indeed as iBug mentioned
words[x - 1] = 'i'; // not "i"
2) plural
is not set to the plural version
// instead of >> plural = strcat(word, "es");
strcpy(plural, word);
strcat(plural, "es");
is what you want.
Upvotes: 0