Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Hi, Im working on a code called a Plurilizer.It is a code in Language C that sca

ID: 3775152 • Letter: H

Question

Hi, Im working on a code called a Plurilizer.It is a code in Language C that scans words from the keyboard and makes them plural and saves both the original form of the word and the plural form in an output file called

pluralWords.txt

Please help because im running into alot of erros. Im trying to make this code so i can implement it into a bigger one.

If the word ends in ‘y’, remove the ‘y’ and add “ies” to the end. Examples: cherry becomes cherries

If the word ends with the letters ‘s’, “ch”, or “sh” then simply add the letters “es” to the end Examples: bus becomes buses

If the above rules above do not apply then just add the letter‘s’ to the end of the word. Examples: Mushroom becomes mushrooms

The program will ask the user if they want to enter a word, then read the word from the keyboard. I am using scanf(“%s”, word); //word is a character array of size 20

After reading each word the program will create an all upper or all lower version of the word and make a copy of that word.

Next it will create the plural form of the word and display it on the screen.

The program will then save the original input word (that is all uppercase or all lowercase), to a file and save the plural form in the same file.

The program will repeatedly read in words in English and output singular and plural words to the file until the user decides to quit

I am using 8 Functions…

o A function that greets the user

o A function that gets the word from the user

o A function that changes the word to all uppercase or all lowercase letters

o A function that determines which rule applies to the word.

o A function for each rule that converts a single word (3 functions)

o A function that saves both words to the output file

This is an example

********* Welcome to the Pluralizer ***********

The output file pluralWords.txt is open

----------------------------------------

Would you like to enter a word Y (YES) or N (NO)? y

Enter a word funny

Rule is 1

Word is FUNNY and plural is FUNNIES

Adding the words to the file

Would you like to enter a word? Y (YES) or N (NO)y

Enter a word bunch

Rule is 2

Word is BUNCH and plural is BUNCHES

Adding the words to the file

Would you like to enter a word? Y (YES) or N (NO)y

Enter a word COLLege

Rule is 3

Word is COLLEGE and plural is COLLEGES

Adding the words to the file

Would you like to enter a word? Y (YES) or N (NO)y

Enter a word FISH

Rule is 2

Word is FISH and plural is FISHES

Adding the words to the file

Would you like to enter a word? Y (YES) or N (NO)n

Thank you for trying out the Pluralizer!

Closing the file pointer

Press any key to continue . . .

Explanation / Answer

hi. Below is the code I had writen with exact specification & output details. Ask me if you have any doubt. I had tested the code & its working as expected.

#include <stdio.h>
#include <string.h>
#include <stdlib.h>   //for exit() fuction

int main()
{
   FILE *fptr;
   char ch='y';
   printf("********* Welcome to the Pluralizer ***********");

   fptr = fopen("pluralWords.txt", "w");
   if (fptr == NULL)
   {
       printf("Error!");
       exit(1);
   }
   printf(" The output file pluralWords.txt is open");
   printf(" ----------------------------------------");

   do
   {
       char word[20];
       char plural[20];
   printf(" Enter a word :");
   gets_s(word, 20);      //get the word

   char substr[5];
   int len = strlen(word);    //get the length of the word
   _strlwr(word);            // to lower case
   memset(substr, '', sizeof(substr));    //intialize the substr with null
   strncpy(substr, word + (len - 2), 2);   //copy the string from word [len-2 to len] to substr
  
   if (word[len - 1] == 'y')
   {
       printf(" Rule is 1 :");
       memset(plural, '', sizeof(plural));
       strncpy(plural, word, len - 1);
       strcat(plural, "ies");                // to concatinate the string
   }
   else if (word[len - 1] == 's')
   {
       printf(" Rule is 2 :");
       memset(plural, '', sizeof(plural));
       strncpy(plural, word, len - 1);
       strcat(plural, "es");
   }
   else if (strcmp(substr, "ch")==0 || strcmp(substr, "sh")==0)
   {
       printf(" Rule is 2 :");
       memset(plural, '', sizeof(plural));
       strncpy(plural, word, len - 2);
       strcat(plural, "es");
   }
   else
   {
       printf(" Rule is 3 :");
       memset(plural, '', sizeof(plural));
       strncpy(plural, word, len);
       strcat(plural, "s");
   }
   printf(" Word is %s and plural is %s", word, plural);
   printf(" Adding the words to the file :");
   fprintf(fptr, "%s", strcat(word, "="));
   fprintf(fptr, "%s", plural);

   printf(" Would you like to enter more word Y (YES) or N (NO)?");
   scanf("%c", ch);
   } while (ch == 'Y' || ch == 'y');

   printf(" Thank you for trying out the Pluralizer!");
   printf(" Closing the file pointer!");
   fclose(fptr);
  
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote