Help with some complex decision making
I am writing a function that searches a linked list(database) against a key of the same type as the struct members of the linked list.
Structure looks like this:
typedef struct Key KEY;
typedef struct Key* KEYS;
so far so good.
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...
sKey.addressee = "Jane Doe"
sKey.sender ="John Doe"
sKey.fname = "0"
sKey.date.month = 11
sKey.date.yeah = 2001
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.
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