1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28
|
void makePlural (const char singular[], char plural[]) //In the word ending with an‘s’, ‘x’, ‘sh’, or ‘ch’, add ‘es’ to make it plural. Otherwise, simply add the letter ‘s’.
{
int n;
n = strlen(singular);
char ch = singular[n - 1];
char ch2 = singular[n - 2];
if (ch == 's' || ch == 'x')
{
strncpy(plural, singular, 23);
strncat(plural, "es", 23);
}
else if (ch == 'h' && ch2 == 's')
{
strncpy(plural, singular, 23);
strncat(plural, "es", 23);
}
else if (ch == 'h' && ch2 == 'c')
{
strncpy(plural, singular, 23);
strncat(plural, "es", 23);
}
else
{
strncpy(plural, singular, 23);
strncat(plural, "s", 23);
}
}
|