title: Function pointer in C?
body: <p>I am beginner in C language and was learning about function pointer in C language. There I encountered a problem?</p>
  <p>Write a compare function to sort by first character of name?</p>
  <p>*int (firstnamecharcompar)(const void * a, const void * b))</p>
  <p>Here is my code solution for this.</p>
  <pre><code>#include&lt;stdlib.h&gt;
  #include&lt;stdio.h&gt;
  #include &lt;stdbool.h&gt;
  
  int compare1(const void *a,const void *b)
  {
      char *c = *(char**)a;
      char *d = *(char**)b;
      return c[0] - d[0];                             
      //return ( *(char*)a[0] == *(char*)b[0] );                
  }
  
  int main()
  {
      char* str[3];
      int i;
      for(i=0;i&lt;3;i++)
      {
          str[i] = (char*)malloc(10*sizeof(char));
      }
      for(i=0;i&lt;3;i++)
      {
          printf(&quot;Enter %d string =&gt; &quot; , i+1 );
          scanf(&quot;%s&quot;, str[i]);                        
          printf(&quot;\n&quot;);
      }
      
      for(i=0;i&lt;3;i++)
      {
          printf(&quot;%s &quot;,str[i]);
      }
      
      qsort(str,3,10,compare1);
      
      for(i=0;i&lt;3;i++)
      {
          printf(&quot;%s &quot;,str[i]);
      }
      return 0;
  }
  </code></pre>
  <p>But my code is getting terminated without giving any output? What is problem with my code?</p>