Hello,
is it (and how is it) possible in C to get the index of an element in the array ? for example, with the 'bsearch' function.
Thanks
well, i think the solution is quite simple:
Code:
int get_index( type element, type* array, int arraysize) {
type *buffer;
buffer = bsearch( &element, array, arraysize, sizeof( type), compare);
if( buffer == NULL)
return -1;
return ((long) buffer - (long) array) / sizeof( type);
}
int compare( void* first, void* second) {
if( (type*) first == (type*) second)
return 0;
...
}