Question

I'm trying to get the index of the element in the array after lfind and bsearch return the pointer to the element that it found. I have this so far:

(char *) (found - cv->baseAddress); 

where found is the address of what the functions found, and the base address is the address of element 0. However, the compiler gives me this error:

cvector.c:150:28: warning: pointer of type ‘void *’ used in subtraction cvector.c:150:4: warning: return makes integer from pointer without a cast

What do I do?

Was it helpful?

Solution

You have to typecast the returned pointer to the correct type. Then you also need to divide the offset you get with the size of the objects in the array to get the index.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top