title: pointers to functions: can't compile
body: <pre><code>#include &lt;stdio.h&gt;
  #include &lt;string.h&gt;
  
  #define MAXLINES 5000
  char *lineptr[MAXLINES];
  
  int readlines(char *lineptr[], int nlines);
  void writelines(char *lineptr[], int nlines);
  
  void qsort(void *lineptr[], int left, int right, int (*comp)(void *, void *));
  
  int numcmp(char *, char *);
  
  int main(int argc, char *argv[])
  {
      int nlines;
      int numeric = 0;
  
      if(argc &gt; 1 &amp;&amp; strcmp(argv[1], "-n") == 0)
         numeric = 1;
      if((nlines = readlines(lineptr, MAXLINES)) &gt;= 0) {
          qsort((void **) lineptr, 0, nlines - 1, (int (*)(void *, void *))(numeric ? numcmp : strcmp));
          writelines(lineptr, nlines);
          return 0;
      } else {
             printf("input too big to sort\n");
             return 1;
      }
  
  
  }
  
  void qsort(void *v[], int left, int right, int(*comp)(void *, void *))
  {
       int i, last;
       void swap(void *v[], int, int);
  
       if(left &gt;= right)
          return;
  
       swap(v, left, (left + right) / 2);
       last = left;
       for(i = left + 1; i &lt;= right; i++) 
          if((*comp)(v[i], v[left]) &lt; 0)
             swap(v, ++last, i);
       swap(v, left, last);
       qsort(v, left, last - 1, comp);
       qsort(v, last + 1, right, comp);
  }
  </code></pre>
  
  <p>This is direct source code from K&amp;R, in chapter pointers and functions, and this is the example they showed about pointers to functions, but I just can't compile the line in which I call QSORT(line 22). I get this:</p>
  
  <pre><code>22 C:\Users\SUZI\Desktop\solutions\Chapter 5\Exercise 5-14\sort.c conditional expression between distinct pointer types `int (*)(char*, char*)' and `int (*)(const char*, const char*)' lacks a cast 
  
  22 C:\Users\SUZI\Desktop\solutions\Chapter 5\Exercise 5-14\sort.c invalid conversion from `int (*)(char*, char*)' to `void*' 
  
  22 C:\Users\SUZI\Desktop\solutions\Chapter 5\Exercise 5-14\sort.c invalid conversion from `int (*)(const char*, const char*)' to `void*' 
  </code></pre>