I need to write a program in C that reads in an english sentence and converts it into piglatin according to 3 rules. All the rules are working correctly; however, it seemes that the program only executes 2 words: the last 2 words in the sentence. Also, since I have played around with fixing that problem, the YES/NO function isnt ececuting properly. Any help would be appreciated, this is only the beginning of the function which is required to have 11 functions.

Here is what i have so far:

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

char *vowel(char *orig);
char *twoletter(char *orig);
char *lastrule(char *orig);
void YesNo(char check);

char newW[80];
char newV[80];
char newD[80];
char newL[80];

int main()
{
	char sentence[1000];
	char piglatin[1000];
	char orig[1000];
    char check;

  int i=0, a=0, b=0, length;
       //clear screen
  printf("Please enter a sentence in all CAPS to be translated into piglatin\n");

  /* Gets sentence stored in array "sentence[]"*/
  while((sentence[i]=getchar())!='\n')
  {
    i++;
  }
  sentence[i]='\0';      //adds null character at end
  length=strlen(sentence);  //# of elements stored in length

  /* Reads a word at a time and checks rule */
  while(a<=length)
  {
    orig[b]=sentence[a];
  
    if(orig[b]==' '||orig[b]=='\0')
    {
      orig[b]='\0';
      b=0;
      
      if(orig[0]=='A'||orig[0]=='E'||orig[0]=='I'||orig[0]=='O'||orig[0]=='U')
      {   
        vowel(orig);//function call for vowel rule
        strcat(piglatin, newV);
        strcat(newV, " ");
        strcpy(newW, newV);
      }//end of if

      else if(orig[0]=='T'&&orig[1]=='H'||orig[0]=='C'&&orig[1]=='H'||orig[0]=='S'&&orig[1]=='H'||orig[0]=='P'&&orig[1]=='H'||orig[0]=='W'&&orig[1]=='H'||orig[0]=='Q'&&orig[1]=='U')
      {
        twoletter(orig);  //function call for 2 letter rule
        strcat(piglatin, newD);
        strcat(newD, " ");
        strcpy(newW, newD);
      }//end of else if
    
      else
      {
        lastrule(orig);  //function call for last rule
        strcat(piglatin, newL);
        strcat(newL, " ");
        strcpy(newW, newL);
      }//end of else

    }//end of if
    else
    {
      strcpy(piglatin, newW);
      b++;
    }//end of else
    
    a++;

  }//end of while

  printf("\nThe length is %d, i= %d:",length,i);
  printf("\n\nYour translated piglatin sentence is: \n%s ", piglatin); 
  printf("\n\nWould you like to enter another sentence to be translated(Y/N)?:  ");
  scanf(" %c", &check);
  YesNo(check);

  return(0);

}//end of main




char *vowel(char *orig)
{
    strcat(orig,"AY");
  strcpy(newV, orig);

return(newV);

}//end of function



char *twoletter(char orig[])
{

char first, append[]="H";

first=orig[0];

if(orig[1]=='H')
{
  orig+=2;      //point at 3rd char
  append[0] = first;  //add on the starting letter
    strcat(orig, append);
    strcat(orig,"HAY");  //and then the 'H' and "AY"
}//end of IF

if(orig[1]=='U')
{
    orig+=2;
    append[0] = first;
    strcat(orig, append);
    strcat(orig, "UAY");
}//end of IF

strcpy(newD, orig);

return(newD);
}//end of function



char *lastrule(char orig[])
{

char first;
char append[]="H";

first=orig[0];    //gets first letter of word

orig++;  
append[0] = first;
strcat(orig,append);
strcat(orig,"AY");
strcpy(newL, orig);

return(newL);
}//end of function



void YesNo(char check)
{

if(check=='Y')
  main();

}//end of function

<< moderator edit: added code tags: [code][/code] >>

Sorry to say, but is is very hard to read this code. You should have used some Coding Standards

To help you solve the problem, I think you are using the same buffer too much. You may need to have more buffers to handle the problem here.

Logically, you read the sentnce from the user, then try to break it into words. What I am suggesting is that you need to seperate and copy each word to a seperate buffer in this program and then should apply the rule.

This would help isolate the problem.

----------------------------------

Programming ( Assignment / Project ) Help

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.