Thanks for your reply on TEk Tips forum (C), I appreciate this.<br>.....I have attached a file "diction.c" (which is a linked list of letters(a,b,c,...,p) which is sorted.<br>Say I am looking for letter 'c' if it exists in the linked list. How do I use bsearch() to find the if match in the linked list ?<br> <br>My Overall Problem:<br>I will READ in a already Sorted List of Words (Dictionary) into Memory - i.e usingOrdered Linked List.<br>I wanted to store the Words in an Array but don't know how many words exist, so cannot declare proper size of array.<br>So I guess I will have to use a linked list<br>Then use bsearch() to locate a KeyWord and see if it exists in the Ordered Linked List. If it can be done.<br>------------------------------------------------------------<br>See my attached file "diction.c" (at bottom page)<br>------------------------------------------------------------<br>BSEARCH: (function I need to use)<br>*bsearch( const void *key, const void * base, size_t nnemb, size_t size, int (*compar)(const void *, const void*) );<br> <br>e.g Search for word 'hello' in array :array[10] stores 10 words<br> <br>bsearch("hello", array, 10, sizeof(array[0]),comp)<br>where compare function is :-<br>int comp (const void *s1, const void *s2)<br>{<br> return (strcmp(*(char **)s1, *(char **)s2));<br>}<br>-----------------------------------------------------------<br>-----------------------------------------------------------<br>#include <stdio.h><br>#include <string.h><br>#include <ctype.h><br>#include <stdlib.h><br><br>int comp(const void *s1, const void *s2);<br><br>typedef struct D_ENTRY_STRUCT LIST;<br>typedef LIST *LISTPTR;<br><br>struct D_ENTRY_STRUCT {<br> char letter;<br> struct D_ENTRY_STRUCT *next_rec;<br>};<br><br>LISTPTR add_to_list ( char, LISTPTR );<br>void show_list( void );<br>void free_memory_list( void );<br><br>LISTPTR first = NULL;<br><br>main ()<br>{<br> LISTPTR rec_addr;<br> int i=0;<br> char letter,ptr;<br><br> rec_addr = add_to_list('a', (LISTPTR)NULL );<br> first = rec_addr;<br> printf("Before Insertion\n"

;<br> while (i++<15)<br> rec_addr = add_to_list('a'+i,rec_addr);<br> show_list();<br> printf("\nCount : %d",i);<br> printf("\nSearch key : "

;<br> letter = getchar();<br>// ptr = (char)bsearch(letter,first,16,sizeof(first),comp);<br>// if (ptr != NULL)<br>// printf("found"

;<br>// else<br>// printf("not found"

; */<br>// free_memory_list();<br> return 0;<br>}<br><br>LISTPTR add_to_list (char ch, LISTPTR prev_rec)<br>{<br> LISTPTR new_rec=NULL;<br><br> new_rec = (LISTPTR)malloc(sizeof(LIST));<br> if (!new_rec)<br> {<br> printf("\nUnable to allocate memory!\n"

;<br> exit(1);<br> }<br><br> new_rec->letter = ch;<br> new_rec->next_rec = NULL;<br><br> if (prev_rec)<br> prev_rec->next_rec = new_rec;<br><br> return(new_rec);<br>}<br><br>void show_list ( )<br>{<br> LISTPTR cur_ptr;<br> int counter=1;<br><br> printf("Rec addr Position Data Next Rec addr\n"

;<br> printf("======== ======== ==== =============\n"

;<br> cur_ptr = first;<br> while (cur_ptr)<br> {<br> printf(" %X ", cur_ptr);<br> printf(" %2i %c",counter++,cur_ptr->letter);<br> printf(" %X \n",cur_ptr->next_rec);<br> cur_ptr = cur_ptr->next_rec;<br> }<br>}<br><br>void free_memory_list ( )<br>{<br> LISTPTR cur_ptr, next_rec;<br> cur_ptr = first;<br> while (cur_ptr)<br> {<br> next_rec = cur_ptr->next_rec;<br> free(cur_ptr);<br> cur_ptr = next_rec;<br> }<br>}<br><br>int comp(const void *s1, const void *s2)<br>{<br> return (strcmp(*(char **)s1, *(char **)s2));<br>}<br><br><br>------------------------------------------------------------<br><br>