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;
}

You need to remove the return of float from your function (make it void), and remove the print in main, asking for a string.

gets() is NOTORIOUSLY unsafe - use fgets() instead.

And indent your program, so it makes sense to read it. It's a mess* this way. The closing brace '}', should be directly underneath (in the same column), as either the opening brace '{', or the first letter of the code that begins the loop:

for(i=0, j=1107;i<MAX;i++) {
  printf("\n%d", i);
  printf(" %d", ++j);
}

for(i=0, j=1107;i<MAX;i++) 
{
  printf("\n%d", i);
  printf(" %d", ++j);
}

Either of the above is a good style. Easy to read, and easy to spot bugs in logic or syntax.

*Mess is being kind.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.