Hi..I have written a C code for that performs well for a 1602X13 size text file. But for 85430X13 size file it is giving Segmentation fault (core dumped) error. I am using gcc compiler and Turbo C both. I am giving the code here for turbo c compiler.
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
void main()
{
int i=0,j,k,x,count=0,n=0,m=13,p=0,q=13;
float s=0.0,dis=0.0;
float * avg;
float ** a;
float ** b;
char buf[BUFSIZ];
FILE *fp1,*fp2,*fp3,*fp4;
clrscr();
fp1=fopen("a1.txt","r");
fp2=fopen("a2.txt","r");
fp3=fopen("result.txt","wb");
while (fgets(buf,sizeof(buf),fp1) != NULL)
n++;
while (fgets(buf,sizeof(buf),fp2) != NULL)
p++;
rewind(fp1);
for(i=0;i<n;i++)
{ a[i] = (float*) malloc(n * m * sizeof(float));
for(j=0;j<m;j++)
{
fscanf(fp1,"%f",&a[i][j]);
}
printf("\n");
}
printf("\n");
rewind(fp2);
for(i=0;i<p;i++)
{ b[i] = (float *) malloc(p * q * sizeof(float));
for(j=0;j<q;j++)
{
fscanf(fp2,"%f",&b[i][j]);
}
printf("\n");
}
printf("\n");
avg = (float *) malloc(n * sizeof(float));
for(x=0;x<=(n-1);x++)
{
if(count!=(n-p)+1){
i=x;k=0;
while(i<(p+x))
{
for(j=0;j<q;j++)
{
s=s+pow((a[i][j]-b[k][j]),2.0);
}
dis=dis+sqrt(s);
s=0;
i++;
k++;
}
count++;
avg[i]=dis;
fprintf(fp3,"%f\n",avg[i]);
dis=0;
}
else
break;
}
getch();
fclose(fp1);
fclose(fp2);
fclose(fp4);
fclose(fp3);
free(a);
free(b);
free(avg);
}