-
You keep track of the number of elements.
Code you wrote:
Code:
double si = sizeof(temp.keys);
This gives you 4 because you probably have 32-bit addresing in your computer. It is the size of a pointer variable, as you declare in your struct.
You actually have added only 3 keys in your code.
You could add the variable n_keys in your struct and drop it from the function.
Also if you set the field keys to NULL before starting doing anything, it will not be necessary to test whether n_keys is zero.
In fact it is a good idea to write a function to initialize yor struct to empty 0 elements, although it can be done more easily like:
I prefer to use a function to initialize structs as it simulates constructor functionality from C++,
and reminds me that my object is fresh and ready ;)