I am trying to get the number of elements in an array of structures so that I can pass it to another function. Struct:
struct info{
char string1[30];
float float1;
int int1;
char string2[30];
};
The section I'm trying to run:
void function1(){
struct info* temp = build();
printf("flag: %lu %lu %lu\n", sizeof(temp), sizeof(temp[0]), sizeof(temp)/sizeof(temp[0]));
sortFloat(temp, sizeof(temp)/sizeof(temp[0]), 1);
free(temp);
}
build () returns an array of structures after reading in the data from the file, where each row will be a structure in the array. I'm having trouble passing the size of the array to sortFloat (). Print line returns
flag: 8 72 0
when there are only two lines in the data file. Hard coding this argument as 2 makes the whole program workable. Why is this method of counting the elements of an array of structures not?
source
share