I have an array of strings called tab.
I want to search for an array in it with the function bsearch() provided by <stdlib.h>.
But I think I am doing something wrong, since it cannot find "delta".
Is my code wrong?
Code:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define LEN(x) (sizeof (x) / sizeof (x[0]))
char *tab[] = {
"alfa",
"beta",
"delta",
"epsilon",
"gama",
"zeta",
};
int
main(int argc, char *argv[])
{
char **t;
char s[] = "delta";
t = bsearch(&s, tab, LEN(tab), sizeof *tab, (int(*)(const void *, const void *)) strcmp);
if (t != NULL)
printf("%s\n", *t);
return EXIT_SUCCESS;
}