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

Hello, I trying to write a C program that translates an English phrase toa Pig L

ID: 3618637 • Letter: H

Question

Hello,
I trying to write a C program that translates an English phrase toa Pig Latin phrase. Rules for Pig Latin language are:
•If a word starts with a consonant and a vowel, put the firstletter of the word at the end of the word and add "ay."
Example: happy = appyh + ay = appyhay
•If a word starts with two consonants move the two consonantsto the end of the word and add "ay."
Example: child = ildch + ay = ildchay
•If a word starts with a vowel add the word "way" at the endof the word.
Example: awesome = awesome +way = awesomeway

The program should have a main function and six subfunctions (inputphrase, create pig latin phrase, get a word, convert word to piglatin word, determine if first character is a vowel, print, andrepeat function). This is what I have so far but it doesn't workand I can't figure it out how to do it right.

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>

#define FLUSH while (getchar() != ' ')

#define MAX_SIZE 256
#define WORD_SIZE 46

void getString (char inputStr[] );
void createPiglatinVersion(char inputStr[]);
int getWord (char inputStr[], char wordStr[], int index);
void getPigLatin(char temp[], char wordStr[], int index);
bool isVowel(char ch);
void printString(char inputStr[], char outputStr[]);
bool repeatOrNot(void);


int main (void)
{

    char inputStr[MAX_SIZE];
    char outputStr[MAX_SIZE];
  
  
    do{
    getString( inputStr );
    createPiglatinVersion(inputStr);
    printString(inputStr, outputStr);
    }while( repeatOrNot() );

    system("pause");
    return 0;
}

void getString (char inputStr [])
{

// Statements
     printf(" Enter a sentence (end with[Enter]):");
     fgets(inputStr, sizeof(inputStr),stdin);
     while (strlen(inputStr)>256)
          {
          FLUSH;
          }
}


void createPiglatinVersion(char inputStr[])
{
     char outputStr[MAX_SIZE];
     char temp[WORD_SIZE];
     char wordStr[WORD_SIZE];
     int index = 0;
     int i;
   
     for(i=0; i<MAX_SIZE; ++i)
          {
          getWord ( inputStr, wordStr, index);
          getPigLatin( temp, wordStr, index);
           if(isalpha(*(inputStr+i))== false)
               outputStr[i]=* (inputStr+i);
          else
              {
               strcpy(outputStr, temp);
               i=i+index;
               }
          }
}

int getWord (char inputStr[], char wordStr[], int index)
{
   
   
     int i;
     for(i=0;i<WORD_SIZE&&isalpha(inputStr[index]);++i);
         {
         wordStr[i]=inputStr[index];
          index++;
          }
     wordStr[i]='';
     return index;
}

void getPigLatin(char temp[], char wordStr[], int index)
{
   char czTemp[WORD_SIZE];
   if(isVowel(*wordStr)!=false&&isVowel(*(wordStr+1)))
   {
       strcpy(temp, wordStr);
       //temp[strlen(temp)+1]='';
       strcat(temp,"ay");
   }
   else if(isVowel(*wordStr)!=false&&isVowel(*wordStr+1)!=false)
   {
       strcpy(temp,wordStr+2);

       czTemp[0] = wordStr[0];
       czTemp[1] = wordStr[1];
       czTemp[2] = '';
       strcat(temp, czTemp);

       //temp[strlen(temp)]=*(--wordStr);
       //temp[strlen(temp)-1]=*(wordStr-2);
       //temp[strlen(temp)+1]='';
       strcat(temp,"AY");
   }
   else if(isVowel(*wordStr))
   {
       strcpy(temp, wordStr);
       // temp[strlen(temp)+1]='';
       strcat(temp,"way");
   }

}

bool isVowel(char ch)
{
     if( ch == 'a' || ch == 'e' || ch == 'i' ||ch == 'o' || ch == 'u' )
        return true;
     else
         return false;
}

void printString(char inputStr[], char outputStr[])
{
// Local Declarations

// Statements
   printf("The string you entered: %s ", inputStr);
   printf("The string converted to Pig Latin: %s ",outputStr);
   printf(" ");
}


bool repeatOrNot ( void )
{
   char answer;

   printf("Try another? (y for yes): ");
   scanf(" %c", &answer);
   printf(" ");
   return toupper(answer)=='Y';
}

Thank you!!


Explanation / Answer

please rate - thanks I gave up on yours here's one I've done, it works, you should be able to break it intothe 6 functions easily. post again, and message me if you can't #include #include #include int main() {int i,j; char str[80]; int choice,isvowel; char vowel[11]={"AEIOUaeiou"},first,second; char *in; char * pch; char wd[50]; printf("Enter a string "); in=gets(str); while(in!=NULL) {pch = strtok (str," ,.-?!;:"); while (pch != NULL) { isvowel=0;     for(i=0;i
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