Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

farmerdoug

macrumors 6502a
Original poster
Sep 16, 2008
541
0
Full code had no compiling error but gave a segmentation error which I fixed by adding the loop for temp. That led to an abort trap a few lines later. I moved the offending code but the abort trap stayed at the same line were price[l] allocation is. Ideas?
Code:
float  **price;

char **temp, ***vol, *date;

temp = (char **) calloc(600,sizeof(char*));
        for (i = 0; i < 2000; i++)
            temp[i] = (char *) calloc(40,sizeof(char));

            
         vol = (char ***) calloc(2,sizeof(char**));
            vol[0] = (char **) calloc(2000,sizeof(char*));
            vol[1] = (char **) calloc(2000,sizeof(char*));
                for(i = 0; i < 2000; i++)
                    {
                    vol[0][i] = (char *) calloc(10,sizeof(char));
                    vol[1][i] = (char *) calloc(10,sizeof(char));
                    }

        date = (char *) calloc(12, sizeof(char));       
        price = (float **) calloc(2000,sizeof(float*));
        for(l = 0; l < 2000; l++)
                price[l] = (float*)calloc(2000,sizeof(float));
 
Code:
temp = (char **) calloc([COLOR="Blue"]600[/COLOR],sizeof(char*));  // A
for (i = 0; i < [COLOR="Red"]2000[/COLOR]; i++)  // B
   temp[i] = (char *) calloc(40,sizeof(char));
A allocates space for 600 char pointers.
B populates the space with 2000 char pointers.

Basic programming principle: Avoid magic numbers.

I didn't bother reading the rest of the code.
 
Farmerdoug, you've been posting code snippets like this for quite a while now. Had you invested some time in learning a higher-level language, it would have paid itself back tenfold by now.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.