All about programming in GNU/LINUX

Improved Linear search code with general function for Search and comparison which can handle any data type…

void *cmp(void *,void *);
void *lsearch(void * ,void *, int ,int);

int main()
int key , n , i;
int *o;
printf(“\nEnter the no.of.Elements: “);
int arr[n];
printf(“\nEnter the key to be searched: “);
printf(“\nThe address of the base = %u and Address of the  match = %u”,&arr[0],o);
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 elmntadd;

printf(“\nMatch not found”);
return NULL;
}//why are we recieving the values are stars
void *cmp(void *key,void *elmntadd)//does the code remains general if this is function is made type specific
char *i=key;//how to work without type casting them ???
char *j=elmntadd;
return *i – *j;//Remove star and ask them
//How to go about if addresses of pointers are sent from key and Elmntadd;


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 )

Twitter picture

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

Facebook photo

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

Google+ photo

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

Connecting to %s