>(void) SysBinarySearch(&pp_array, (UInt) count, (UInt) sizeof(sort_element),
> (SearchFuncPtr) &search_routine,
> &id, (ULong) 0, &searchpos, false);
The first parameter to SysBinarySearch should be a pointer to the start of your
data. You're passing a pointer to the pointer to the start of your data. Try
passing "pp_array" instead of "&pp_array".
> data = (*(sort_element *)arrayData)->id;
This compiles??? Shouldn't that be "((sort_element *)arrayData)->id;"?
-- Keith
"Thomas Ward" <[EMAIL PROTECTED]> on 12/10/99 11:58:10 AM
Please respond to [EMAIL PROTECTED]
Sent by: "Thomas Ward" <[EMAIL PROTECTED]>
To: [EMAIL PROTECTED]
cc: (Keith Rollin/HQ/3Com)
Subject: SysBinarySearch and search function
Hi everyone,
Has anybody been able to make SysBinarySearch work? This is what I have:
GLOBAL:
typedef struct {
ULong id;
int order;
} sort_element;
sort_element *pp_array;
IN A SUBROUTINE:
ULong searchpos;
(void) SysBinarySearch(&pp_array, (UInt) count, (UInt) sizeof(sort_element),
(SearchFuncPtr) &search_routine,
&id, (ULong) 0, &searchpos, false);
Right before this call, I've verified that the pp_array contains the proper
values, and that the COUNT variable is correct.
MY SEARCH ROUTINE:
static int search_routine(const VoidPtr searchData,
const VoidPtr arrayData, Long other) {
ULong search, data;
int answer;
CALLBACK_PROLOGUE
search = *((ULong *) searchData);
data = (*(sort_element *)arrayData)->id;
if (search < data)
answer = -1;
else if (search > data)
answer = 1;
else
answer = 0;
CALLBACK_EPILOGUE
return answer;
}
The SEARCH variable contains the correct value, but the value in DATA is
always wrong. Can anybody tell me what I'm doing wrong? (I have a feeling
it's the assignment statement DATA = ... that's the problem.)
TIA,
Tom Ward