I have the following functions :
Code:
typedef struct
{
char authors[5][40]; // first and last names of the author
char title[150]; // title of the publication
unsigned int year; // year of the publication
char isbn[15]; // publication code
} PubEntryT;
NodeST *findS(ListST *L, void *pKey, void * (*itemKey)(void *pItem), int(*keyCmp)(void *pKey1, void *pKey2))
// returns a pointer to the cell having a key equal to the one pointed to by pKey – if such a node exists
// on the list – or NULL if it cannot find such a node.
{
NodeST *p;
if (L != NULL)
{
if (L->first != NULL)
{
p = L->first;
while ( p != NULL)
{
if ( keyCmp ( itemKey (p->Item),pKey) == 0)
break;
p=p->next;
}
}
else {
//errorSmessage(2);
return NULL;
}
}
return p;
}
void *itemKeyIsbn(void *pItem)
{ // for returning the isbn field of a book record
return ((PubEntryT *) pItem)->isbn;
}
int keyCmpStr(void *pKey1, void *pKey2)
{ // comparison of two ASCIIZ string keys; good for author or isbn comparison
return strcmp((char *)pKey1, (char *)pKey2);
}
I have to call this functions to find the node with a given key (a certain isbn, for example) and I use this call:
p = findS(L, pItem->Item,itemKeyIsbn(pItem),keyCmpStr(pItem->Item, pItem->Item)));
I'm not sure that my call is correct. In fact, I get segmentation fault in findS at the line
Code:
( keyCmp ( itemKey (p->Item),pKey) == 0)