I have an array of sruct sockaddr_in:
struct sockaddr_in saddrlist[MAX] = {0};
the array is also being updated from external sources with memcpy, so thats the point where i dont know anymore about the count. and currNumOfelements.
Now at some point, i want to check how many elements are in the array. What I tried:
printf("before: %d",getsize(saddrlist));
memcpy(&myotherlist, saddrlist, sizeof(saddrlist) * MAX);
printf("after: %d",getsize(saddrlist));
Which results in:
before: 52448
after: 52448
int getsize(struct sockaddr_in saddrlist[10])
{
uint8_t numOfElements = 0;
for (size_t i = 0; i < MAX; i++)
if (saddrlist[i] != 0)
numOfElements++;
}
This obviously doesn't work because if (saddrlist[i] != 0) is an invalid comparison.. but how do i do it then? I get so confused using c..
currNumOfElementsthen?currNumOfElementstoo, or that it provides some other mechanism to determine whether it changed the number of valid elements.