?
=?ISO-8859-1?Q?Jonathan_Gro=DF?=
Hi everybody,
in the sample below my programm gives a "Bus error" on the marked line.
I don't get it why that happens. I followed the instructions in the
C-FAQ.
#include <math.h>
#include <stdlib.h>
#define dim 2
#define length 3
int main (int argc, const char * argv[]) {
int i,j;
int volume=(int)pow(length,dim);
int **nbrs = (int **) malloc(volume * sizeof(int *));
for (i=0; i<volume; i++)
*(nbrs+i) = (int *) malloc(2*dim * sizeof(int));
for (i=0;i<volume;i++)
for(j=0;j<(2*dim);j++) {
*(nbrs+i)=i;
*(*(nbrs+i)+j)=j; //here is the problem
}
for (i=0; i<volume; i++)
printf("%d\n", nbrs);
return 0;
}
in the sample below my programm gives a "Bus error" on the marked line.
I don't get it why that happens. I followed the instructions in the
C-FAQ.
#include <math.h>
#include <stdlib.h>
#define dim 2
#define length 3
int main (int argc, const char * argv[]) {
int i,j;
int volume=(int)pow(length,dim);
int **nbrs = (int **) malloc(volume * sizeof(int *));
for (i=0; i<volume; i++)
*(nbrs+i) = (int *) malloc(2*dim * sizeof(int));
for (i=0;i<volume;i++)
for(j=0;j<(2*dim);j++) {
*(nbrs+i)=i;
*(*(nbrs+i)+j)=j; //here is the problem
}
for (i=0; i<volume; i++)
printf("%d\n", nbrs);
return 0;
}