用C语言编写一个程序输入名词并根据以下规则给出复数形式:

来源:百度知道 编辑:UC知道 时间:2024/05/04 12:33:26
a) 如果名词以“y”结尾,删除“y”并添加“ies”。
b) 如果名词以“s”、“ch”或“sh”结尾,添加“es”。
c) 其他所有情况,直接添加“s”。
打印每个名词和它的复数形式。尝试以下数据:
chair dairy boss circus fly dog church clue dish
一楼的那个答案能不能写得再简单通俗易懂点?我是初学者

#include <stdio.h>
#include <conio.h>

int main(int argc, char* argv[])
{
char word[256];
int pos = 0;

while (1)
{
scanf("%s", word);
pos = strlen(word);
if (word[pos-1] == 'y')
{
word[pos-1] = '\0';
strcat(word, "ies");
}
else if ((word[pos-1] == 's')
|| ((word[pos-2] == 'c')&&(word[pos-1] == 'h'))
|| ((word[pos-2] == 's')&&(word[pos-1] == 'h')))
{
strcat(word, "es");
}
else
{
strcat(word, "s");
}
printf("%s\n", word);
}
getch();
return 0;
}