Pig Latin for help
Mar 3, 2012 at 2:55pm UTC
Hi, I was just playing around with Pig Latin & I came across this codes somewhere. I was trying to debug it, there was no error but I got weird error like this.
Input: happy
Pig Latin: 汤汤汤汤汤汤汤汤汤汤汤汤汤汤汤汤汤汤汤汤汤 appyhay
Any c++ expert know how can i fix it? Thanks.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30
#include <stdio.h>
#include <string.h>
#define SIZE 90
void convertPigLatin(char *word, char *piglatin);
main()
{
char word[SIZE];
char piglatin[SIZE];
printf("Input: " );
scanf("%s" , word);
convertPigLatin(word, piglatin);
printf("Pig Latin: %s\n" , piglatin);
}
void convertPigLatin(char *word, char *piglatin)
{
char *pig_latin="ay" ;
char *after, *before;
while (strchr("aeiouAEIOU" ,*word) == NULL)
{
char consonant=*word;
piglatin=word, before=word+1;
while (*before)
*piglatin++=*before++;
*piglatin=consonant;
}
strcat(piglatin, pig_latin);
}
Mar 3, 2012 at 3:10pm UTC
WRONG.
RIGHT.
And though I didn't test it, I suppose that
char piglatin[SIZE] = {0};
might fix it.
Last edited on Mar 3, 2012 at 3:11pm UTC
Mar 3, 2012 at 6:32pm UTC
hi thanks for the advice! I tried your method but it only print "ay" for every words instead of the converted words.
Mar 3, 2012 at 6:45pm UTC
Its useless program buddy its just prints "ay".Nothing else.
Mar 3, 2012 at 7:09pm UTC
yeah it do only prints "ay." hi spacecamp, do you know what wrong with the code?
Mar 3, 2012 at 11:43pm UTC
Topic archived. No new replies allowed.