Good morning, thanks in advance for the help. I am creating a pig latin translator for a class (with that in mind, sorry for bad coding form) and I am having trouble. I have my function working, but it seems like I am stuck in a loop. I'm having trouble finding my problem. Please help! Also, how would I then translate a pig latin phrase to english?
#include <stdio.h>
#include <string.h>
#include <conio.h>
/*function prototypes*/
float convert2pl (char engstr [ 100 ]);
int main()
{
char str[ 100 ];
convert2pl (str);
printf("\n");
printf("Enter a string (CTRL^Z enter to exit)");
return 0;
}
float convert2pl (char str [ 100 ])
{
int i,j;
int isvowel;
char vowel [ 11 ] = { "AEIOUaeiou" }, one, two;
char *in;
char *engpnc;
char plout [ 100 ];
printf("Enter a string\n ");
in = gets( str );
while(in != NULL)
{engpnc = strtok (str," ,.-?!;:"); /*tokenize punctuation*/
while (engpnc != NULL)
{ isvowel=0;
for(i=0;i<10;i++)
if(engpnc[0]==vowel[i])
isvowel=1;
if(isvowel)
{for(j=0;j<strlen(engpnc);j++)
if(engpnc[j]!='\n')
plout[j]=engpnc[j];
plout[j]='\0';
strcat(plout,"ay");
}
else
{ for(i=0;i<10;i++)
if(engpnc[1]==vowel[i])
isvowel=1;
if(isvowel)
{one=engpnc[0];
for(j=1;j<strlen(engpnc);j++)
if(engpnc[j]!='\n')
plout[j-1]=engpnc[j];
if(engpnc[j]=='\n')
j--;
plout[j-1]=one;
plout[j]='\0';
strcat(plout,"ay");
}
else
{one=engpnc[0];
two=engpnc[1];
for(j=2;j<strlen(engpnc);j++)
if(engpnc[j]!='\n')
plout[j-2]=engpnc[j];
if(engpnc[j-1]=='\n')
j--;
plout[j-2]=one;
plout[j-1]=two;
plout[j]='\0';
strcat(plout,"ay");
}
}
for(j=0;j<strlen(plout);j++)
printf ("%c",plout[j]);
printf(" ");
engpnc = strtok (NULL, " ,.-?!;:");
}
}
return 0;
}