This is a question i copy from others,and i write the code but nid u to help figure out problem.
User is required to enter a sentence in English to be transformed to Pig-Latin form. To transform a word to Pig-Latin form, the first letter of the word beginning with a consonant is moved to the back, added with letters ay after the moved consonant. Words that begin with a vowel are simply appended with ay. You can assume the user will not key in any punctuations or uppercase letters.
Example 1:
Please enter a sentence: this is an english sentence
Pig-Latin form: histay isay anay englishay entencesay
Example 2:
Please enter a sentence: hope you have fun
Pig-Latin form: opehay ouyay avehay unfay
My work is
#include <stdio.h>
#include <stdlib.h>
#include<ctype.h>
void initialize(char english[],char piglatin[]);
void readinput(char english[]);
int countwords(char english[]);
void convert(int words,char english[],char piglatin[]);
void writeoutput(char piglatin[]);
main()
{
char english[80],piglatin[80];
int words;
printf("welcome to the Piglatin Generator");
printf("Type \'End\' when finished\n\n");
do
{
initialize(english,piglatin);
readinput(english);
if( toupper(english[0])=='E' &&
toupper(english[1])=='N'&&
toupper(english[2])=='D') break;
words= countwords(english);
convert(words,english,piglatin);
writeoutput(piglatin);
}
while(words>=0);
printf("naveha aa icena ayda");
}
void initialize(char english[],char piglatin[])
{
int count;
for(count=0;count<80;++count)
english[count]= piglatin[count]=' ';
return;
}
void readinput(char english[])
{
int count=0;
char c;
while((c=getchar())!='\n')
{
english[count]=c;
++count;
}
return;
}
int countwords(char english[])
{
int count,words=1;
for(count=0;count<79;++count)
if(english[count]==' '&&english[count+1]!=' ')
++words;
return(words);
}
void convert(int words,char english[],char piglatin[])
{
int n,count;
int m1=0;
int m2;
for(n=1;n<=words;++n)
{
count=m1;
while(english[count]!=' ')
m2=count++;
for(count=m1;count<m2;++count)
piglatin[count+(n-1)]=english[count+1];
piglatin[m2+(n-1)]= english[m1];
piglatin[m2+n]= 'a' ;
m1=m2+2;
}
return;
}
void writeoutput(char piglatin[])
{
int count=0;
for(count=0;count<80;++count)
putchar(piglatin[count]);
printf("\n");
return;
}
Now the problem i face in my code is
how to reach the requirement " the first letter of the word beginning with a consonant is moved to the back, added with letters ay after the moved consonant. Words that begin with a vowel are simply appended with ay"?