#include #include #include // function prototypes //function prototype that asks
ID: 3618169 • Letter: #
Question
#include
#include
#include
// function prototypes
//function prototype that asks the user to enter a word
void
//function prototype that uses strcpy to copy the original word from the word array to the newword array
void
//function prototype that uses the rules for words
void
//function that takes one string argument and file pointer and saves the word to a file
void
//Asks the user if they want to enter another word.
void
int
{
FILE *outptr;
outptr= fopen(
Enter(word);
CopyString(newword, word);
SaveWord(word,outptr);
SaveWord(newword,outptr);
Rules(word, newword);
Quit(&again);
printf(
}
}
// function definitions
//Asks the user if they want another snack.
void
{
printf(
scanf(
}
//function definition that asks the user to enter a word and reads it from the user
void
{
printf(
scanf(
Explanation / Answer
x.Xce="Courier New">#define _CRT_SECURE_NO_DEPRECATE #include #include #include void Enter(char word[]); void CopyString(char word[], char newword[]); void Rules(char word[], char newword[]); void SaveWord(char word[], FILE *outptr); void Quit(char *again); int main(){ char again =' '; char word[20]=""; char newword[20]=""; FILE *outptr; outptr= fopen("out.txt","w"); do{ Enter(word); CopyString(newword, word); SaveWord(word,outptr); SaveWord(newword,outptr); Rules(word, newword); Quit(&again); printf(" choice entered %c ", again); }while(again!='n'&& again!='N'); } void Quit(char *again){ printf(" Would you like to enter another word yes(y) or no(n): "); scanf("%c", again); } //function definition that asks the user to enter a word and reads it from the user void Enter(char word[]) { printf(" Enter a word: "); scanf("%s", word); } //function definition that uses strcpy to copy the original word from the word array to the newword array void CopyString(char newword[], char word[]) { strcpy(newword, word); } //function definition that uses the a conditional to figure out which rule to use and add the plural addition by strcat void Rules(char word[], char newword[]){ int length; length = strlen(word); if (word[length-1] == 'Y'){ strcat(&newword[length-1],"IES"); printf("Rule is 1"); } else if (word[length-1] == 'y'){ strcat(&newword[length-1],"ies"); printf("Rule is 2"); } else if ((word[length-1] == 'H' && word[length-2] == 'C') || (word[length-1] == 'H' && word[length-2] == 'S') || (word[length-1] == 'S')){ strcat(&newword[length-1],"ES"); printf("Rule is 3"); } else if ((word[length-1] == 'h' && word[length-2] == 'c') || (word[length-1] == 'h' && word[length-2] == 's') || (word[length-1] == 's')){ strcat(&newword[length-1],"es"); printf("Rule is 4"); } else if (isupper(word[length-1])){ strcat(&newword[length-1],"S"); printf("Rule is 5"); } else if(islower(word[length-1])){ strcat(&newword[length-1],"s"); printf("Rule is 6"); } } void SaveWord(char word[], FILE *outptr){ printf(" ------------------------------------ "); printf(" The word on the screen is: %s ", word); fprintf(outptr," The word in the file is: %s ", word); }Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.