Sam, this looks really awful: double **array1; array1 [HEIGHT][WIDTH]; do you mean: double **array1; //array1 [HEIGHT][WIDTH]; But this might not be your probablem. You say " folder which has about 200 text files", but your code is treating this as "exactly 200 text files", you need to do something there. Then again please recall the reminder of Jim Bosch and maybe post this problem on a different list, maybe stackexchange? -Holger On Mon, Sep 30, 2013 at 5:40 PM, sam <asu_mcs@yahoo.com> wrote:
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
_______________________________________________ Cplusplus-sig mailing list Cplusplus-sig@python.org https://mail.python.org/mailman/listinfo/cplusplus-sig