S
Sheldon
Hi,
I would like to view the contents of structure as part of a debugging
routine.
The structure is represented by a pointer ptr->data.
I would like to view the first element in the array, data. This is part
of debugging this program.
A problem occured when a 2D binary array: ptr->data was copied to the
another array in another structure via memcpy(). Since the codes is
big, I will only post the relevant parts I feel is needed - I might be
wrong. Here is a summary:
******************************************
struct hdfstruct {
float** latitude;
} hdfdata;
int main(void) {
printf("Allocating memory!\n");
hdfdata.latitude = calloc(ROW,sizeof(float *));
if(hdfdata.latitude == NULL) {
fprintf(stderr, "Failed to allocate memory\n");
return EXIT_FAILURE;
}
for (i = 0; i < 15; i++) {
hdfdata.latitude = calloc(15,sizeof(float));
if(hdfdata.latitude == NULL) {
fprintf(stderr, "Failed to allocate memory\n");
return EXIT_FAILURE;
}
}
/* Reading the hdf data into the arrays */
stat = readHDF(hdfdata.latitude,latfile,"/LAT");
}
int readHDF(float **arp, char *hdfname, char *fieldname) {
/* omitted the parts concerning extracting the data */
/* I didn't write it so I kow that it works */
memcpy(arp, cloudproduct->data, 15*15*4);
return (1) /* zero is returned on error */
}
*************************************
Now I don't want to sent the structure into the readhdf function as I
will be calling the function many times so it is necessary to send a
pointer instead. Still the results is that the entire 2D array has the
same value and this is wrong. The codes runs without error but an error
ocurred somewhere.
To summerize: I am wondering if there is a way to view a structure like
in python: print list and to comfirm my suspicion about the memcpy to
the pointer.
I certainly hope that I gave enough info to get some help.
Thanks in advance,
Sheldon
I would like to view the contents of structure as part of a debugging
routine.
The structure is represented by a pointer ptr->data.
I would like to view the first element in the array, data. This is part
of debugging this program.
A problem occured when a 2D binary array: ptr->data was copied to the
another array in another structure via memcpy(). Since the codes is
big, I will only post the relevant parts I feel is needed - I might be
wrong. Here is a summary:
******************************************
struct hdfstruct {
float** latitude;
} hdfdata;
int main(void) {
printf("Allocating memory!\n");
hdfdata.latitude = calloc(ROW,sizeof(float *));
if(hdfdata.latitude == NULL) {
fprintf(stderr, "Failed to allocate memory\n");
return EXIT_FAILURE;
}
for (i = 0; i < 15; i++) {
hdfdata.latitude = calloc(15,sizeof(float));
if(hdfdata.latitude == NULL) {
fprintf(stderr, "Failed to allocate memory\n");
return EXIT_FAILURE;
}
}
/* Reading the hdf data into the arrays */
stat = readHDF(hdfdata.latitude,latfile,"/LAT");
}
int readHDF(float **arp, char *hdfname, char *fieldname) {
/* omitted the parts concerning extracting the data */
/* I didn't write it so I kow that it works */
memcpy(arp, cloudproduct->data, 15*15*4);
return (1) /* zero is returned on error */
}
*************************************
Now I don't want to sent the structure into the readhdf function as I
will be calling the function many times so it is necessary to send a
pointer instead. Still the results is that the entire 2D array has the
same value and this is wrong. The codes runs without error but an error
ocurred somewhere.
To summerize: I am wondering if there is a way to view a structure like
in python: print list and to comfirm my suspicion about the memcpy to
the pointer.
I certainly hope that I gave enough info to get some help.
Thanks in advance,
Sheldon