R
Ramprasad A Padmanabhan
I have written a simple script to search a word in an array But bsearch
does not seem to work here.
I know I am missing out something very simple , But I am not able to
find out what
Thanks
Ram
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <error.h>
int cmp1(const void *p1, const void *p2)
{
char *s = p1;
char *target = p2;
printf("Comparing %s ==> %s \n",s,target);
return(strcmp(s,target));
}
int main(int argc,char* argv[]){
int i=0;
char* find[] = {"a.c","b.c","c.c","END"};
char* words[] ={"a.c","b.c","c.c","zzz"};
while(strcmp(find,"END") != 0){
char *tmp;
tmp = bsearch(find, words, 4,4, cmp1);
printf("Finding word %s\t==>\t Got %s\n",find,tmp);
i++;
}
return(0);
}
My output looks like this
Finding word a.c ==> Got (null)
Finding word b.c ==> Got (null)
Finding word c.c ==> Got (null)
does not seem to work here.
I know I am missing out something very simple , But I am not able to
find out what
Thanks
Ram
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <error.h>
int cmp1(const void *p1, const void *p2)
{
char *s = p1;
char *target = p2;
printf("Comparing %s ==> %s \n",s,target);
return(strcmp(s,target));
}
int main(int argc,char* argv[]){
int i=0;
char* find[] = {"a.c","b.c","c.c","END"};
char* words[] ={"a.c","b.c","c.c","zzz"};
while(strcmp(find,"END") != 0){
char *tmp;
tmp = bsearch(find, words, 4,4, cmp1);
printf("Finding word %s\t==>\t Got %s\n",find,tmp);
i++;
}
return(0);
}
My output looks like this
Finding word a.c ==> Got (null)
Finding word b.c ==> Got (null)
Finding word c.c ==> Got (null)