Hi there. I am working on a relative file structure with a table index. I have a binary search algorithm to search the index for and input key but I am afraid this binary search has me stumped!
Any help would be much appreciated.
Jesse

int Search(char InputKey[])
{
FILE *Index;
int Relative;
int Start = 0;
int Middle;
long End = filelength(Index) / sizeof Address;
int Location = -1;


while ((Location = -1)&&(Start <= End))
{
Middle = ((Start + End) / 2) *sizeofFileAddress;
fseek(Index, Middle , SEEK_SET);
fread(&FileAddress, sizeof FileAddress, 1, Index);

if (strcmp(FileAddress.Key, InputKey) == 0)
Location = Middle * sizeof FileAddress;
else
if (strcmp(FileAddress.Key, InputKey) < 0)
Start = Middle + 1;
else
// if (strcmp(Car.chassis, InputKey) > 0)
End = Middle - 1;
}

if (Location = -1)
puts("\nRecord key does not exist.\n");
else
{
fseek(Index, Location, SEEK_SET);
Relative = ftell(Index);
}
getch();
return Relative;
}