#include <stdio.h>                 
#include <stdlib.h>                
#include <stdint.h>       
#include <ctype.h>
#include <string.h>                

static char inputBuffer[100];
static char outputBuffer[100];

int isAlpha(char alpha){
	
	if ((alpha >= 'a' && alpha <= 'z') || (alpha >= 'A' && alpha <= 'Z'))
		return 1;
	else
		return 0;
}

int isVowel(char c)
{
	c = tolower(c);
    if (c == 'a' || c == 'e' || c == 'i' || c == 'o' || c == 'u')
        return 1;
    return 0;
}

void translate (void)
{
  char bufferValue;
  char firstLetter;
  int j = 0, k = 0, m = 0;

  printf("\n");
  int size = strlen(inputBuffer);
  
  while (j < size)
  {
    bufferValue = inputBuffer[j];

    if (isAlpha(bufferValue))
    {
    	if (j == 0) 
    	{
        	firstLetter = bufferValue;
      	}
    	else if (inputBuffer[j-1] == ' ') 
      	{
        	firstLetter = bufferValue;                                      
      	}
      	else
      	{
        	printf("%c", bufferValue);
        	outputBuffer[m] = bufferValue;
        	m++;
      	}
    }    
    else if ((bufferValue == ' ') && isAlpha(inputBuffer[j - 1]))
    {
    	
    	outputBuffer[m] = firstLetter; m++;
    	if (!isVowel(firstLetter)){
    		printf("%cay%c", firstLetter, bufferValue);
    		outputBuffer[m] = 'a';
    		m++;
    	}
    	else{
    		printf("%cy%c", firstLetter, bufferValue);
    	}
    	outputBuffer[m] = 'y'; m++;
    	outputBuffer[m] = bufferValue; m++;
    	firstLetter = ' ';
    }
    else
    {
    	if (isAlpha(firstLetter)){
    		
    		outputBuffer[m] = firstLetter; m++;
    		if (!isVowel(firstLetter)){
    			printf("%cay", firstLetter);
	    		outputBuffer[m] = 'a'; m++;
    		}
    		else{
    			printf("%cy", firstLetter);
    		}
    		outputBuffer[m] = 'y'; m++;
    		firstLetter = ' ';
    	}
    	printf("%c", bufferValue);
      	outputBuffer[m] = bufferValue; m++;
    }
    j++;

  } 

  printf("\n final output: %s",outputBuffer);

   return;
}

int main(void)
{
  printf("enter the string\t");
  fflush(stdin);
  gets(inputBuffer);

  printf ("\nInput buffer contents:  %s", inputBuffer);
  translate();
  return 0;             
} 