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

x.Hmking on a program in C that converts English into Pig Latin. Ihave it almost

ID: 3618777 • Letter: X

Question

x.Hmking on a program in C that converts English into Pig Latin. Ihave it almost done but I have two problems and I don't know how to fixthem. The first one is when I enter a sentence it only prints andconverts the first word. And the second one is that I doesn't print thepunctuation symbols.

Thank you!

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

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

#define STR_LEN 256
#define WORD_SIZE 46

void getInput ( char inputStr[] );
void createPigLatinString ( char outputStr[], char inputStr[], int size);
int getWord (char inputStr[], char wordStr[], int index);
void createPigLatinOfWord (char outputStr [], char wordStr[], char* pch,char inputStr[]);
char isVowel(char ch);
void printString(char inputStr[], char outputStr[]);
bool repeatOrNot ( void );


int main (void)
{
    char inputStr[STR_LEN];
    char outputStr[STR_LEN];
  
    do
    {
     getInput ( inputStr );
     createPigLatinString ( outputStr, inputStr, STR_LEN );
     printString ( inputStr, outputStr );
     }while( repeatOrNot() );
  
  
return 0;
}

void getInput ( char inputStr[] )
{
// Statements

   printf(" Enter a sentence (end with [Enter]): ");
   fgets( inputStr, STR_LEN, stdin );
   FLUSH;

}

void createPigLatinString ( char outputStr[], char inputStr[], int size )
{
     char wordStr[WORD_SIZE];
     char *pch;
     int index;
     int i;
   
     for(i=0; i<STR_LEN; i++)
     {
     createPigLatinOfWord(outputStr, wordStr, pch, inputStr);
     strcat(outputStr,wordStr);
     strcat(outputStr," ");
     }
}



void createPigLatinOfWord (char outputStr [], char wordStr[], char* pch,char inputStr[])
{
int choice;
int isvowel;
int i;
int j;
int k;
char first;
char second;
int t;


outputStr[0]='';
pch = strtok (inputStr," ,.-?!;:");
while (pch != NULL)
{
            isvowel=isVowel(pch[0]);
        if(isvowel)
              {for(j=0;j<strlen(pch);j++)
               if(pch[j]!=' ')
                  wordStr[j]=pch[j];
               wordStr[j-1]='';
               strcat(wordStr,"way");
              }
         else
            {isvowel=isVowel(pch[1]);
            if(isvowel)
              {first=pch[0];
              for(j=1;j<strlen(pch);j++)
                 if(pch[j]!=' ')                    
                     wordStr[j-1]=pch[j];
              if(pch[j]==' ')
                   j--;
               wordStr[j-2]=first;             
               wordStr[j-1]='';
               strcat(wordStr,"ay");            
               }
             else
                {first=pch[0];
                second=pch[1];
              for(j=2;j<strlen(pch);j++)
                 if(pch[j]!=' ')                    
                     wordStr[j-2]=pch[j];
              if(pch[j-1]==' ')
                   {j--;
                   k=j;
                   }
               wordStr[j-2]=first;
               wordStr[j-1]=second;            
               wordStr[j]='';
               strcat(wordStr,"ay");            
               }
              }

    pch = strtok (NULL, " ,.-?!;:");
}

}


char isVowel(char ch)
{
int i;
char vowel[11]={"AEIOUaeiou"};
for(i=0;i<10;i++)
    if(ch==vowel[i])
        return 1;
return 0;
}

void printString(char inputStr[], char outputStr[])
{
// Statements
   printf("The string you entered: %s", inputStr);
      
&n

Explanation / Answer

x.Hlor="red">please rate - thanks this is for characters. to add the punctuation it will have to be rewritten without strtok #include #include #include #include #define FLUSH while (getchar() != ' ') #define STR_LEN 256 #define WORD_SIZE 46 void getInput ( char inputStr[] ); void createPigLatinString ( char outputStr[], char inputStr[], int size ); int getWord (char inputStr[], char wordStr[], int index); void createPigLatinOfWord (char outputStr [], char wordStr[], char* pch, char inputStr[]); char isVowel(char ch); void printString(char inputStr[], char outputStr[]); bool repeatOrNot ( void ); int main (void) {     char inputStr[STR_LEN];     char outputStr[STR_LEN];           strcpy(outputStr," ");        do     {      getInput ( inputStr );      createPigLatinString ( outputStr, inputStr, STR_LEN );      printString ( inputStr, outputStr );      }while( repeatOrNot() );       return 0; } void getInput ( char inputStr[] ) { // Statements    printf(" Enter a sentence (end with [Enter]): ");    fgets( inputStr, STR_LEN, stdin ); // FLUSH; } void createPigLatinString ( char outputStr[], char inputStr[], int size ) {      char wordStr[WORD_SIZE];      char pch[100];      int index;      int i;         createPigLatinOfWord(outputStr, wordStr, pch, inputStr);      strcat(outputStr," "); } void createPigLatinOfWord (char outputStr [], char wordStr[], char* pch, char input[]) { int choice; int isvowel; int i; int j; int k; char first; char second; int found; int index; char inputStr[STR_LEN]; strcpy(inputStr,input); outputStr[0]=''; pch = strtok (inputStr," ,.-?!;:"); while (pch != NULL) { if(isalpha(pch[0]))       {found=0;       isvowel=isVowel(pch[0]);         if(isvowel)               {for(j=0;j