Function prototype looks like this
list = the linked list (all the records in our database)
sKey = a search key.
both containing all the same members of the defined struture.

KEY search(KEYS list, KEY sKey )

First of all I check to see if there is a match for unique data.
if(sKey.fname) or if(sKey.id) This is fine. There is no need to search any further if we have these. It's when we don't have these things get a little more complex.

The real problem here is that the search criteria could be wide (1 search term) or very narrow (4 search terms)

So consider one instance for example. A user wishes to search the linked list by "sender" and "addressee". This should return a list of matching nodes from the data we are searching. So ALL nodes in the list that match where John Doe send Jane Doe an email will be pulled up from our linked list (it's a database)

The rest of the "unknown" data is initialized to "0" before being passed into the search function.
i.e looking at each value of this in the debugger...

Sure, it's easy to compare any ONE of the members of this structure to all the nodes in the list that's passed in.

BUT when you have to compare MORE than one things get hairy.
If I could see an example of this complex if statement it might help me to write the rest.

Thanks,
Mike

ps...Just incase you wish to see the code or have it run locally...
it's in the zip attached.
It's got everything needed to build and run.
I am working inside of search.c
the value for sKey is built and passed from Menu.c to give me stuff to pass in so I can test my work.
use command line arg keylist.dat

11-17-2001

QuestionC

Perhaps you could use a function that takes two keys and returns 1 or zero if the first key meets the criteria for the second key?

That's a hell of a return statement, eh? I'm not sure it's all syntactically correct, but the idea is that it goes through each element of the structure, and for each element, it checks to see if the search value is 0, or if the search value is the same as the other value passed. The way I wrote it, key1 is the search value, and key2 is the value you are checking to see whether it matches key1's criteria. If I might make a suggestion though, instead of using "0", maybe you should try using something like NULL, or an empty string... it's just kinda a good C-habit to use.

11-17-2001

mlupo

Unfortunately,
this is being integrated into a design. I cannot call anything outside of the standard C library. I can't add any new functions to the flow.

I am only writing the search function for this database. I am blind to what else is going on around the search() function.

So I am sorta in a pickle.

Does the If statement you wrote (mine actually resembles yours) cover ALL the cases? or should I implement several if statements using this design one for each "first" member to check?

;)

Thanks

11-17-2001

mlupo

QuestionC,
thanks for your input.
I looked at your example. I implemented the idea in my code. It works!
Yippee!!