In C: How do you find the number of elements in an array of structs, after sending it to a function?
int main(void) {
myStruct array[] = { struct1, struct2
Note that in main(), array refers to the actual array and so sizeof() gives the required answer.
But when you pass it as function parameter,you are actually passing the address of the first element of the array which is stored in the pointer variable 'array'.
So now sizeof() gives the size of pointer variable which is why it differs from actual answer.
Possible solution can be to
1.Declare the array globally
2.Pass the array size as function parameter Hope it helps!