I am having some issues with two arrays in C. Specifically, I pass two arrays to a function, malloc them and fill them with data and when I try to use them in my main program I get a segmentation fault.
int readData(FILE *f, int * regionSize, float **regions)
{
regionSize = (int *)calloc(10,sizeof(int));
// Fill regionSize
regions = (float **)malloc(10*sizeof(float *));
for(i=0;i<10;i++)
{
regions[i] = (float*)malloc(regionSize[i]*sizeof(float));
}
// Fill regions
// Everything prints ok here
return 0;
}
int main(int argc, char **argv)
{
int *regionSize;
float **regions;
readData(f,regionSize, regions);
printf("print------------------------\n");
for(i=0;i<10;i++)
{
for(j=0;j<userRegionsSize[i];j+=4) // SEGMENTATION FAULT HERE
{
//print
}
}
}
What am I missing?