I don't know why I didn't see this earlier:
Code:
random=rand()%h+1;
bootarray[aa][0]=barray[random][col1];
bootarray[aa][1]=barray[random][col2];
That's why your program crashes.
edit - when in doubt, range check:
Code:
void bootstrapping (int h, int w, double barray[h][w], int col1, int col2)
{
if( h > 0 && w > 0 && col1 < w && col1 > -1 && col2 < w && col2 > -1 )
{
int random = 0;
long aa = 0, bb = 0, b = 0; /* your variable names leave a lot to be desired */
float bootresults[1000] = {0}, a = 0.0, cc = 0.0;
double bootarray[h][2] = { { 0.0, 0.0 } }, *r = NULL;
FILE *bootfp = NULL;
r=malloc( ACCU * sizeof *r );
if( r == NULL )
return; /* do something, you have no memory */
bootfp = fopen("bootstrap.results", "w");
if( bootfp == NULL )
return; /* do something, fopen failed */
for(aa=0;aa<ACCU;aa++) r[aa]=0.0;
for(aa=0;aa<1000;aa++) bootresults[aa]=0.0;
srand((unsigned) time(NULL)); /* do this in main() */
for(bb=0;bb<ACCU;bb++){
for(aa=0;aa<h;aa++){ //Fill in a random selection of sets to an equal height array
random=rand()%h;
bootarray[aa][0]=barray[random][col1];
bootarray[aa][1]=barray[random][col2];
} //aa
r[bb]=pearson_product_moment_coefficient(h, 2, bootarray, 0, 1);
printf("%f\n", r[bb]); // <======================This line!!!!
} //bb
for(aa=0;aa<ACCU;aa++) {
b=r[aa]*1000;
if( b < 1000 && b > -1 )
bootresults[b]++;
else
{
/* handle your error */
}
} //aa
for(aa=0; aa<1000; aa++){ //print the final result to the file
a=(aa*0.1)/(1000*0.1);
fprintf(bootfp, " %-5.3f %-8.0f\n", a, bootresults[aa]);
} // ii
fclose(bootfp);
free( r );
}
}
Quzah.