title: C Programming: Singular to plural nouns
body: <p>my program here is supposed to </p>
  
  <p>Write a program that takes nouns and forms their plurals on the basis of thee rules:</p>
  
  <ol>
  <li>If noun ends in “y”, remove the “y” and add “ies”.</li>
  <li>If noun ends in “s”, “c”, “ch”, or “sh”, add “es” .</li>
  <li>In all other cases, just add “s”.</li>
  </ol>
  
  <p>Print each noun and its plural.</p>
  
  <p>It works fine, when I enter word such as dairy it prints dairies, but it loops and prints dairieseseseseseseseseseseses...etcetc. I was hoping this is a quick fix that I can't find and somebody can help me with it!</p>
  
  <p>Thanks!</p>
  
  <pre><code>#include &lt;stdio.h&gt;
  #include &lt;string.h&gt;
  
  
  
  #define max_word 20
  
  
  
  /* prototypes */
  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);
   }
  
    return;
  }
  
  void pluralize (char word[])
  {
    int length;
    char noun;
    length=1;
    length = strlen(word);
  
     if (word[length - 1] == 'y') 
   {   word[length - 1] = 'i';
       word[length] = 'e';
      word[length + 1] = 's';
      word[length + 2] = '\0';  
    }
  
  
    /* if word ends in "s" "ch" or "sh" add "es" */
  
   else if (word[length - 1] == 's' ||
      (word[length - 2] == 'c' &amp;&amp; word[length - 1] == 'h') ||
      (word[length - 2] == 's' &amp;&amp; word[length - 1] == 'h'))
    {  strcat(word, "es");
    }
  
    else
   {   strcat(word, "s");
  
      printf("New word is: ", &amp;noun);
  } 
  return;
  }
  </code></pre>