#include <stdio.h>
#include <stdlib.h>
#include <string.h>


void smarty(char*str)
{
	char* word1=strtok(str," ");
	char* newstr=(char*)malloc(strlen(word1)+1);
	char* word2=strtok(NULL," ");
	while(str!=NULL)
	{
		if(strcmp(word1,word2)==0)
		{
			newstr=(char*)realloc(str,strlen(str)+strlen(word1)+1);
			strcat(newstr," ");
			strcat(newstr,word1);
		}
		else
		{
			newstr=(char*)realloc(str,sizeof(newstr)+(sizeof(word1))+(sizeof(word2)));
			strcat(newstr," ");
			strcat(newstr,word1);
			strcat(newstr," ");
			strcat(newstr,word2);
		}
		word1=strtok(NULL," ");
		word2=strtok(NULL," ");
		str+=strlen(word1)+strlen(word2)+2;
	}
}
void main()
{
	char str[]="penis burger burger vurger penis";
	smarty(str);
	getch();
}