A
a
After taking advice from previous replies, 1D and 2D arrays are allocated
by:
#define SIZE 12
smark = calloc(SIZE,sizeof(struct tagged_array*));
for(i=0;i<SIZE;i++) {
smark = calloc(SIZE,sizeof(struct tagged_array));
}
omark = calloc(SIZE,sizeof(struct tagged_array*));
for(i=0;i<SIZE;i++) {
omark = calloc(SIZE,sizeof(struct tagged_array));
}
sdist = calloc(SIZE,sizeof(struct tagged_array*));
for(i=0;i<SIZE;i++) {
sdist = calloc(SIZE,sizeof(struct tagged_array));
}
odist = calloc(SIZE,sizeof(struct tagged_array*));
for(i=0;i<SIZE;i++) {
odist = calloc(SIZE,sizeof(struct tagged_array));
}
assg_under_chair = calloc(SIZE,sizeof(int *));
for(i=0;i<SIZE;i++) {
assg_under_chair = calloc(SIZE,sizeof(int));
occ=0;
}
The values of the array are perfectly correct. But in the following loop,
for (k=0; k<SIZE; k++) { //for each chairman, id only, no
location implication
for (kk=0; kk<SIZE; kk++) { //moving to diff location
cost = 0;
for (j=0; j<SIZE; j++) { //objecting other chairmen in
other rows
for (jj=0; jj<SIZE; jj++) { //objecting other chairmen
in other rows
printf(" a: %d ", assg_under_chair[j][jj] ) ;
if ( assg_under_chair[j][jj] == k ) {
cost = cost + ( (odist[kk][jj].value) * (occ[k]) );
printf("3: %lf %lf %lf \n",cost ,
odist[kk][jj].value , occ[k] );
break;
}
}
}
}
}
the three %lf are all zeros. But once out of this loop, the values PRINTED
OUT immediately become normal again. Would anybody know what happens?
by:
#define SIZE 12
smark = calloc(SIZE,sizeof(struct tagged_array*));
for(i=0;i<SIZE;i++) {
smark = calloc(SIZE,sizeof(struct tagged_array));
}
omark = calloc(SIZE,sizeof(struct tagged_array*));
for(i=0;i<SIZE;i++) {
omark = calloc(SIZE,sizeof(struct tagged_array));
}
sdist = calloc(SIZE,sizeof(struct tagged_array*));
for(i=0;i<SIZE;i++) {
sdist = calloc(SIZE,sizeof(struct tagged_array));
}
odist = calloc(SIZE,sizeof(struct tagged_array*));
for(i=0;i<SIZE;i++) {
odist = calloc(SIZE,sizeof(struct tagged_array));
}
assg_under_chair = calloc(SIZE,sizeof(int *));
for(i=0;i<SIZE;i++) {
assg_under_chair = calloc(SIZE,sizeof(int));
occ=0;
}
The values of the array are perfectly correct. But in the following loop,
for (k=0; k<SIZE; k++) { //for each chairman, id only, no
location implication
for (kk=0; kk<SIZE; kk++) { //moving to diff location
cost = 0;
for (j=0; j<SIZE; j++) { //objecting other chairmen in
other rows
for (jj=0; jj<SIZE; jj++) { //objecting other chairmen
in other rows
printf(" a: %d ", assg_under_chair[j][jj] ) ;
if ( assg_under_chair[j][jj] == k ) {
cost = cost + ( (odist[kk][jj].value) * (occ[k]) );
printf("3: %lf %lf %lf \n",cost ,
odist[kk][jj].value , occ[k] );
break;
}
}
}
}
}
the three %lf are all zeros. But once out of this loop, the values PRINTED
OUT immediately become normal again. Would anybody know what happens?