I need to write a pig latin program but i can not figure out how to make it skip just to the vowel not just the first letter. this is what i have.
#include %26lt;stdio.h%26gt;
#include %26lt;string.h%26gt;
void printLatinWord(char *a);
int main(void)
{
char phrase[1000];
char *token;
printf("Enter the phrase to translate:\n");
gets(phrase);
printf("\nThe sentence in Pig Latin is:\n");
token = strtok(phrase, " ");
printLatinWord(token);
printf("\n");
return 0;
}
void printLatinWord(char *a)
{
char *word = a;
while (word != NULL)
{
printf("%s%c%s", word + 1, word[0], "ay ");
word = strtok(NULL, " ");
printf(" ");
}
}
C program help Please?
Try this:
void printLatinWord(char *a)
{
/* while the first char is not a vowel */
while (strchr("aeiouAEIOU",*a) == NULL)
{
char consonant=*a; /* save the first char */
char *to=a, *from=a+1;
/* shift bytes left within the word */
while (*from) *to++=*from++;
*to=consonant; /* put the consonant at the end */
}
printf("%say ", a);
}
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment