#include<stdio.h>
void main()
{
FILE *a[10];
int i,j,k;
float b[10][4][4];
for(i=0;i<8;i++)
{
char filename[100];
sprintf(filename,"infile%d.txt",i);
a[i]=fopen(filename,"r");
}
for(i=0;i<8;i++)
{
for(j=0;j<2;j++)
{
for (k=0;k<3;k++)
{
fscanf(a[i],"%f",&b[i][j][k]);
}
}
}
for (i=0;i<8;i++)
{
printf("\n-----------------%d--------------------",i);
for(j=0;j<2;j++)
{
for(k=0;k<3;k++)
{
printf("\nb[%d][%d][%d]=%f",i,j,k,b[i][j][k]);
}
}
}
}
I have written the above code in C. Which just reads 8 different files and print it in terminal. The file name is infile0, infile1 and son on up to infile7. Though the code runs, it shows segmentation fault core dumped in the terminal. I couldn't figure out why this happens at all. Can some one help me figure out the mistake in the code.