Please add comments Write a C program that takes nouns and f
Please add comments!
Write a C program that takes nouns and forms their plurals on the basis of these rules:
a. If noun ends in \"y\", remove the \"y\" and add \"ies\".
b. If noun ends in \"s\", \"ch\", or \"sh\" add \"es\".
c. In all other cases, just add \"s\".
print each noun and its plural. try the following data:
chair dairy boss circus fly dog church clue dish
Solution
#include <stdio.h>
#include <string.h>
#define MAX 50
void pluralform (char word[]);
int main (void) {
/* declarations */
char temp[MAX]; /* stores temporary word entered by user */
/* prompt user to enter noun */
printf(\"Please Enter a noun in singular form: \");
scanf(\"%s\", temp);
while (strcmp(temp, \"done\") != 0) {
/* convert noun into plural form */
pluralform (temp);
/* print the plural form of the word */
printf(\"The plural form is %s\ \", temp);
/* Ask user to enter noun */
printf(\"Please type in a noun in singular form: \");
scanf(\"%s\", temp);
}
return 0;
}
/* Return values: none, but word[] will be changed through this function
* functionality: changes word[] to be the plural form of word[]
*/
void pluralform (char word[]){
/* declarations */
int length;
/* Calculate length of word */
length = strlen(word);
/*If word ends in \"y\" then change to \"ies\" */
if (word[length - 1] == \'y\') {
word[length - 1] = \'i\';
word[length] = \'e\';
word[length + 1] = \'s\';
word[length + 2] = \'\\0\'; /* remember to put \'\\0\' at end of string */
}
/* If word ends in \"s\" \"ch\" or \"sh\" add \"es\" */
else if (word[length - 1] == \'s\' ||
(word[length - 2] == \'c\' && word[length - 1] == \'h\') ||
(word[length - 2] == \'s\' && word[length - 1] == \'h\')){
/* concatenate \"es\" to word */
strcat(word, \"es\");
}
/* otherwise add \"s\" to the end of word */
else {
strcat(word, \"s\");
}
}

