i need to store the piglatin words returned by each function into one string so that I can then check it for lowercase or uppercase words and change as required. I can't seem to get the return 'temp' to store into a string in main. Also, when printed out, the last 2 or 3 letters move to the next line, why is this?
Here is my code thus far: must enter info in all CAPS for now.
#include<stdio.h>
#include<ctype.h>
#include<string.h>
char * vowel_rule(char *);
char * two_letter(char *);
char * last_rule(char *);
void rules();
int main()
{
rules();
return(0);
}
void rules()
{
char str[80];
char english[80];
int length,a,b,i;
i=0;
a=b=0;
printf("Please enter a phrase to be translated to piglatin: ");
fgets(str,79,stdin);
length = strlen(str);
printf("\nThis is your translated sentence: ");
while(a<=length)
{
english[b]=str[a];
if(english[b]==' '||english[b]=='\0')
{
english[b]='\0';
b=0;
if(english[0]=='A'||english[0]=='E'||english[0]=='I'||english[0]=='O'||english[0]=='U'||english[0]=='a'||english[0]=='e'||english[0]=='i'||english[0]=='o'||english[0]=='u')
{
printf(" %s",vowel_rule(english));
}
else if(english[0]=='T'&&english[1]=='H'||english[0]=='C'&&english[1]=='H'||english[0]=='S'&&english[1]=='H'||english[0]=='P'&&english[1]=='H'||english[0]=='W'&&english[1]=='H'||
english[0]=='t'&&english[1]=='h'||english[0]=='c'&&english[1]=='h'||english[0]=='s'&&english[1]=='h'||english[0]=='p'&&english[1]=='h'||english[0]=='w'&&english[1]=='h'||english[0]=='Q'&&english[1]=='U'||english[0]=='q'&&english[1]=='u')
{
printf(" %s",two_letter(english));
}
else
{
printf(" %s",last_rule(english));
}
}
else
{
b++;
}
a++;
}
}
char * vowel_rule(char *str)
{
static char temp[80];
memset(temp,'\0',80);
strcpy(temp,str); //copy word starting from second character to temp
temp[strlen(temp)+1]= '\0'; // Null terminate temp
strcat(temp,"AY"); // append "ay" to the string.
return temp;
}
char * two_letter(char *str)
{
static char temp[80];
memset(temp,'\0',80);
char first,append[]="H";
first=str[0];
if(str[1]=='H')
{
strcpy(temp,str+=2); //copy word starting from second character to temp
append[0]=first;
strcat(temp,append);//copy the first char of word to end of temp
temp[strlen(temp)+1]='\0'; // Null terminate temp
strcat(temp,"HAY"); // append "HAY" to the string.
}
if(str[1]=='U')
{
strcpy(temp,str+=2); //copy word starting from second character to temp
append[0]=first;
strcat(temp,append);//copy the first char of word to end of temp
temp[strlen(temp)+1]='\0'; // Null terminate temp
strcat(temp,"UAY"); // append "HAY" to the string.
}
return temp;
}
char * last_rule(char *str)
{
static char temp[80];
memset(temp,'\0',80);
strcpy(temp,++str); //copy word starting from second character to temp
temp[strlen(temp)]=*(--str); //copy the first char of word to end of temp
temp[strlen(temp)+1]= '\0'; // Null terminate temp
strcat(temp,"AY"); // append "way" to the string.
return temp;
}