Hello,
I am just learning C so this might be an obvious question so bare with me....
I am writing a small program, much like grep. I search the files sent in and look for a search word. Like grep I am trying to add functionaility for an ignore case search. I want to use a pointer to a function. The functions I will use will take two char pointers and return int.
Here is a snippet of my code:
Code:
int (*comp)(char *, char *);
if(!ignore_case)
comp = notexact;
else
comp = exact;
int success = search_line(next_line, find, &search_word, comp);
I haven't made notexact yet but exact is defined as:
Code:
int exact(char *string1, char *string2)
{
return(strcmp(string1, string2));
}
Instead of returning strcmp, I figured it would be faster to send in a pointer to strcmp like so:
Code:
int (*comp)(char *, char *);
if(!ignore_case)
comp = notexact;
else
comp = strcmp;
//comp = exact;
However, when I compile this I get the following error:
warning: assignment from incompatible pointer type
Why won't this work? Isn't strcmp defined exactly as my function exact?
Thanks for any help or pointers.....no pun intended
Later