#include<stdio.h>
#include<stdlib.h>
#include<time.h>
#include<string.h>
#ifdef _WIN32
	#include<conio.h>
	#include<Windows.h>
#endif


void main()
{
	int i,j,k,l,g;
	char t1[5][20001]={NULL};
	char t2[3][101]={NULL};

	char t1t2[15][20102];

	char t2t1[15][20102];
	char temp='\0';
	double start, end;
	FILE *fp1, *fp2, *fp3;
	fp1=fopen("T1data.txt", "w+");
	fp2=fopen("pointer_result.txt", "w+");
	fp3=fopen("notpoint_result.txt", "w+");

	printf("\ncreated a T1 : SAVE T1data.txt\n");
	for(i=0; i<5; i++)
	{
		for(j=0;j<20000;j++)
		{
			temp=rand()%26+65;
			fprintf(fp1, "%c", temp);
			t1[i][j]=temp;
		}
		t1[i][j]='\0';
		fprintf(fp1, "\n");
	}


	printf("\nImage of T2\n");
	for(i=0;i<3;i++)
	{
		fflush(stdin);
		scanf("%s",t2[i]);
	}

	printf("\nImage of T2\n");
	for(i=0;i<3;i++)
	{
		printf("<%s>\n",t2[i]);
	}

	printf("\n POINTER T1 & T2");
	printf("\n    SAVE pointer_result.txt\n");
	start = clock();

	for(g=0;g<100;g++)
	{
		k=0;
		for(j=0;j<3;j++)
		{
			for(i=0;i<5;i++)
			{
				strcpy(t1t2[k],t1[i]);
				strcat(t1t2[k],t2[j]);
				k++;
			}

		}
	}
	end = clock();
	for(i=0;i<15;i++)
	{
		fprintf(fp2, "%s\n",t1t2[i]);
	}
	printf("Execution time : %.3lf(ms)\n", (end-start)*1000.0/CLOCKS_PER_SEC);


	printf("\n NOT POINTER T1 & T2");
	printf("\n    SAVE notpointer_result.txt\n");
	temp='\0';
	start = clock();   

	for(g=0;g<100;g++)
	{
		k=0;
		for(j=0;j<3;j++)
		{
			for(i=0;i<5;i++)
			{
				for(l=0;l<20001;l++)
				{               
					if(t1[i][l]=='\0')
					{
						strcpy(t1t2[k],t1[i]);   
					}               
				}
				strcat(t1t2[k],t2[j]);
				k++;
			}         
		}
	}
	end = clock();

	for(i=0;i<15;i++)
	{
		fprintf(fp3, "%s\n",t1t2[i]);
	}

	printf("Execution time : %.3lf(ms)\n", (end-start)*1000.0/CLOCKS_PER_SEC);
	fclose(fp1);
	fclose(fp2);
	fclose(fp3);
	system("PAUSE");
}