title: initialization discards ‘const’ qualifier from pointer target type
body: <p>I have an array structs that hold char names. I want to sort them alphabetically using qsort however I keep getting an error message saying &quot;initialization discards ‘const’ qualifier from pointer target type&quot;. I believe my cmpmi() function and qsort arguments are correct. Any help is greatly appreciated!</p>
  <p>My error is:</p>
  <pre><code>gcc -std=gnu11 -Werror -Wall -o main main.c -lm -g
  main.c: In function ‘compmi’:
  main.c:18:25: error: initialization discards ‘const’ qualifier from pointer target type [-Werror=discarded-qualifiers]
    const student_t **p1 = a;
                           ^
  main.c:19:25: error: initialization discards ‘const’ qualifier from pointer target type [-Werror=discarded-qualifiers]
    const student_t **p2 = b;
                           ^
  cc1: all warnings being treated as errors
  makefile:2: recipe for target 'main' failed
  make: *** [main] Error 1
  
  </code></pre>
  <p>This is my qsort function:</p>
  <pre><code>int compmi(const void *a, const void *b)
  {
      const student_t **p1 = a;
      const student_t **p2 = b;
      return strcmp((*p1)-&gt;name, (*p2)-&gt;name);
  }
  </code></pre>
  <p>Code:</p>
  <pre><code>int main(int argc, char **argv) {
      unsigned numrecords;
      int i = 0;
      int length_multiplier = 1;
      char *lettergrade;
      //char *input = NULL;
      //char *pItem;
      
      student_t **students = NULL;
      // OPENS THE FILE IN BINARY
      FILE *input_file;
      input_file = fopen(&quot;input.bin&quot;, &quot;rb&quot;);
      // READS THE NUMBER OF RECORDS
      fread(&amp;numrecords, sizeof(u_int32_t), 1, input_file);
      
      // LOOPING THROUGH EACH ENTRY
      for(i = 0; i &lt;= numrecords; i++)
      {
          // ALLOCATES MEMORY
          students = realloc(students, sizeof(student_t *) * length_multiplier);
          students[i] = malloc(sizeof(student_t));
          
          students[i]-&gt;name = malloc(sizeof(student_t)* 20);
          fread(students[i]-&gt;name, sizeof(student_t), 20, input_file);//READ NAME
          fread(&amp;students[i]-&gt;gpa, sizeof(student_t), 1, input_file); // READ GPA
          fread(&amp;students[i]-&gt;age, sizeof(u_int32_t), 1, input_file);// READ AGE
          
          length_multiplier++;
          
      }
      //SORTING WITH QSORT
      qsort(*students, numrecords, sizeof(student_t *), compmi);
  
      // PRINTING OUTPUT
      for(i = 0; i &lt; length_multiplier - 2 ; i++)
      {
          printf(&quot;%i of %d:\n&quot;, i + 1, numrecords);
          printf(&quot;Name: %s\n&quot;, students[i]-&gt;name);
          //printf(&quot;UPDATED GPA USE THIS: %.1f\n&quot;, students[i]-&gt;gpa);
          printf(&quot;GPA:  %.1f \n&quot;, students[i]-&gt;gpa);
          printf(&quot;Age:  %i\n&quot;, students[i]-&gt;age);
          printf(&quot;\n&quot;);
      }
      
      // FREEING MEMORY
      for(i = 0; i &lt; length_multiplier; i++)
      {
          free(students[i]);
          
      }
      free(students);
      fclose(input_file);
      
      return 0;
  }
  </code></pre>