[C++-sig] fault core dump error
sam
asu_mcs at yahoo.com
Mon Sep 30 17:40:29 CEST 2013
Hello,
I wrote a C program that loop inside a folder which has about 200 text files. Each file has almost 60000 lines. I created 2D array [60000][200] to store files in it. No compilation problem at all, but when I try to run it I get this error (fault core dump). Yes I did use malloc()
This is my code:
///////////////
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>
#define WIDTH 200 // total number of files
#define HEIGHT 60000 // total number of lines for each file
int main ()
{
double **array1; array1 [HEIGHT][WIDTH];
int w ,h;
int fnum = 1;
char filename [64];
double *data;
FILE * fpr;
FILE * fpw;
// reading files data to array1
array1 = (double **) malloc(HEIGHT*sizeof(double));
for (w=0;w<WIDTH;w++)
{
sprintf(filename, "C:/User/data%d.txt", fnum);
;
fpr = fopen(filename, "r");
for (h=0;h<HEIGHT;h++)
{
array1[h] = (double *) malloc(WIDTH*sizeof(double));
fscanf(fpr, "%lf", &array1 [h][w]);
fclose(fpr);
}
fnum ++;
}
return 0;
}
////////////////
Thank you,
Sam
More information about the Cplusplus-sig
mailing list