Click here to Skip to main content
15,921,454 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have no idea about how to do the part below
I am a new learner and I could not finish createPiglatinVersion part
thanks
create a Pig Latin version of the original string (may be several words, for the whole line of input) and save in another string --MAKE SURE YOU DON'T GO OUTSIDE THE ARRAY BOUNDS, and DON'T CHANGE THE ORIGINAL STRING! Be sure to copy the non-letters to the new string, and copy the pig-latin versions of the words in place of an input word to the new string

Here is the work I have done

<pre lang="cs">#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>

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

#define MAX_SIZE 256
#define WORD_SIZE 46

void getString (void);
void createPiglatinVersion(char *inputStr);
int getWord (char *inputStr,char *wordStr, int index);
void getPigLatin(char *temp, char *wordStr, int index);
bool isVowel(char oneword);
void printString(char *inputStr, char *outputStr);
bool repeatFcn(void);


int main (void)
{
    char oneword='y';
    printf("%d",isVowel(oneword));

    system("pause");
    return 0;
}

void getString (void)
{
     char inputStr[MAX_SIZE];

     printf("\nEnter a sentence (end with [Enter]):");
     fgets(inputStr, sizeof(inputStr), stdin);
     while (strlen(inputStr)>255)
          {
           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)
          {
           outputStr
           getWord ( inputStr,wordStr, index);
           getPigLatin( temp,  wordStr, 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]='\0';
     return index;
}

void getPigLatin(char *temp, char *wordStr, int index)
{
     if(isVowel(*wordStr)!=false&&isVowel(*wordStr+1))
         {
          strcpy(temp, wordStr);
          temp[strlen(temp)+1]='\0';
          strcat(temp,"ay");
          }
     else if(isVowel(*wordStr)!=false&& isVowel(*wordStr+1)!=false)
         {
          strcpy(temp,wordStr+2);//copy word starting from second character to temp
          temp[strlen(temp)]=*(--wordStr);//copy the first char of word to end of temp
          temp[strlen(temp)-1]=*(wordStr-2);
          temp[strlen(temp)+1]= '\0'; // Null terminate temp
          strcat(temp,"AY");          // append "AY" to the string.
          }
     else if(isVowel(*wordStr))
         {
          strcpy(temp, wordStr);
          temp[strlen(temp)+1]='\0';
          strcat(temp,"way");
          }

}

bool isVowel(char oneword)
{
     oneword = toupper(oneword);
     return ((oneword=='A' || oneword=='E' || oneword=='I' || oneword=='O' || oneword=='U')&&(oneword!='Y'));
}


void printString(char *inputStr, char *outputStr)
{
     printf("The string you entered: %c\n", *inputStr);
     printf("The string converted to Pig Latin: %c\n", *outputStr);
}

bool repeatFcn(void)
{
     char check;

     printf("\nTry another? (y for yes): ");
     scanf(" %c", &check);
     if(check=='Y'||check=='y')
         return true;
     else
         return false;
}
Posted

1 solution

You are not making it clear what your question is. Try to ask a more specific question and include just the code for the part that is not working. That way you are likey to get more answers. :)

Good Luck :thumbsup:
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900