string compare Code , with a core Function called Lsearch which is capable of handling any data type , The CMP function is type specific.



void *cmp(void *str1,void *str2);
void *lsearch(void *key,void *base,int n,int size);
int main()
char *str[]={“karttttttttttttt”,”elephantsec”,”elephant”,”Eb”,”D#”,”C#”};
char *key=”elephant”;//hops
printf(“\n%d\n”,sizeof(char **));
lsearch(&key,str,5,sizeof(char *));

return 0;

void *lsearch(void *key,void *base,int n,int size)
int i;
void *elmntadd=(char *)base+(i*size);
if(cmp(key,elmntadd)==0)//why are sending values
printf(“Match found at %dth position”,i+1);
return 0;

printf(“\nMatch not found”);
return NULL;
void *cmp(void *str1,void *str2)
char *s1=*(char **)str1;
char *s2=*(char **)str2;


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s