Step 1 has been completed but not sure how to get the other two steps to work as
ID: 440539 • Letter: S
Question
Step 1 has been completed but not sure how to get the other two steps to work as well. Please advise on what I need to do next. #include void PigLatin(char String[]); int main(void) { char String[37]; printf("Please enter a word (up to 34 characters in length): "); fgets(String, 35, stdin); //passing in a sizeof = 35 (two less than the actual size of the array PigLatin(String); return 0; } void PigLatin(char String[]) { int i; for(i = 0; i < 35; ++i) //move first letter to end of word then null terminate { if(String[i] == '') { String[i - 1] = String[0]; String[i] = 'a'; String[i + 1] = 'y'; String[i + 2] = ' '; break; } } i = 1; while(String[i] != '') //move all characters left by one element { String[i - 1] = String[i]; String[i] = ''; ++i; } printf("The Pig Latin equvalent of the word you entered is: %s", String); } Steps needed to be used to run program This lab focuses on the manipulation of c-strings. The user will be prompted to enter a word. They will then be given a menu with the following options: 1. Pig Latin 2. Count Vowels & Consonants 3. Quit MENU ITEM 1: Pig Latin is a form of coded language often used for amusement. Many variations exist in the methods used to form pig-Latin phrases. For simplicity, use the following algorithm: 1. Move the first letter of the word to the end 2. Add the lettersExplanation / Answer
#include #include #include void Menu(void); void ValidationControl(int *Selection); void PigLatin(char String[]); void CharacterCount(char String[], int *TotalCount, int *VowelCount); int main(void) { int Selection = 0; while(Selection != 3) { do { Menu(); Selection = getchar(); char Trash[2]; fgets(Trash, sizeof(Trash), stdin); ValidationControl(&Selection); } while(Selection == -1); switch(Selection) { case 1: { //Pig Latin //int Continue; //do //{ //printf("Enter 3 to return to the main menu "); //Continue = getchar(); //char Trash[2]; //fgets(Trash, sizeof(Trash), stdin); //ValidationControl(&Continue); char String[37]; //supercalifragilisticexpialidocious (34 characters) + 2 for "ay" + 1 for NULL memset(String, 0, sizeof(String)); printf("Please enter a word (up to 34 characters in length): "); fflush(stdout); fgets(String, 35, stdin); //passing in a sizeof = 35 (two less than the actual size of the array printf(" "); PigLatin(String); //} while(Continue != 3); //selection to "return to the main menu") break; } //end case 1 case 2: { //Count Vowels & Consonants //int Continue; //do //{ //printf("Enter 3 to return to the main menu "); //Continue = getchar(); //char Trash[2]; //fgets(Trash, sizeof(Trash), stdin); //ValidationControl(&Continue); char String[100]; int TotalCount = 0; int VowelCount = 0; memset(String, 0, sizeof(String)); printf ("Enter a sentence: "); fgets(String, 100, stdin); CharacterCount(String, &TotalCount, &VowelCount); printf("The total number of characters is: %d ", TotalCount); TotalCount = TotalCount - VowelCount; printf("You entered: %d total consonants and %d total vowels ", TotalCount, VowelCount); //} while(Continue != 3); //selection to "return to the main menu") break; } //end case 2 } //end switch } //end outer while return 0; } //end main void Menu(void) { printf("Please select one of the following (you may Quit from the main menu at any time): "); printf("1.Pig Latin "); printf("2.Count Vowels & Consonants "); printf("3.Quit "); } //end function void ValidationControl(int *Selection) //function to validate the user's entry { int ValidSelection = 0; if((isdigit(*Selection) != 0)) //it is a number 0 - 9 { //printf("Line 182: Value of Selection is: %d", *Selection); ValidSelection = atoi(Selection); //convert the ascii value to it's corresponding number //printf("Line 184: Value of ValidSelection is: %d", ValidSelection); char Trash[2]; fgets(Trash, sizeof(Trash), stdin); if(ValidSelection != 1 && ValidSelection != 2 && ValidSelection != 3) //it isn't 1, 2, or 3 { printf("Line 190: Invalid selection. "); *Selection = -1; } //end second nested if else if(ValidSelection == 1 || ValidSelection == 2 || ValidSelection == 3) { if(ValidSelection != 3) { *Selection = 0; } else if(ValidSelection == 1) { *Selection = 1; } else if(ValidSelection == 2) { *Selection = 2; } else { *Selection = 3; } } //end second nested else } //end outer if else { printf("Line 220: Invalid selection. "); //printf("Line 121: Value of Selection is: %d", *Selection); //printf("Line 122: Value of ValidSelection is: %d", ValidSelection); } } //end function void PigLatin(char String[]) { int i; for(i = 0; i < 35; ++i) //move first letter to end of word, tack on 'a' and 'y' then null terminate { if(String[i] == '') { String[i - 1] = String[0]; String[i] = 'a'; String[i + 1] = 'y'; String[i + 2] = ' '; break; } } i = 1; while(String[i] != '') //shift all characters left by one element then null terminate { String[i - 1] = String[i]; String[i] = ''; ++i; } printf("The Pig Latin equvalent of the word you entered is: %s ", String); } //end function void CharacterCount(char String[], int *TotalCount, int *VowelCount) { const char Vowels[11] = {'a', 'A', 'e', 'E', 'i', 'I', 'o', 'O', 'u', 'U', ''}; char Store; int i, j; for(i = 0; String[i] != ''; ++i) { if(isalpha(String[i]) != 0) { ++*TotalCount; } } for(i = 0; Vowels[i] != ''; ++i) { Store = Vowels[i]; for(j = 0; String[j] != ''; ++j) { if(Store == String[j]) { ++*VowelCount; } } } } //end functionRelated Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.