title: C Program double free or corruption error
body: <p>Currently working on a concordance program in C. When I try to run the program though, I get an error. </p>
  
  <p>This is my C program: </p>
  
  <pre><code>#include &lt;stdio.h&gt;
  #include &lt;stdlib.h&gt;
  #include &lt;string.h&gt;
  #include &lt;ctype.h&gt;
  
  
  void print(char Table, int n) {
      printf("%d: ", n+1); // Prints the table
  }
  
  int insert(const void *bb, const void *cc) {
      return strcmp(*(const char **)bb, *(const char **)cc);
  }
  
  void empty(char *Table[]) {
      strcat(Table,"NULL"); // Empties the table
  }
  
  int main(int argc, char *argv[]){
  
  
      if(argc!=3){
          printf("ERROR: Usage: concordance table_size"); // Errors due to not enough variables (Should be tablesize and file name)
      } else {
  
          FILE *fp;  //This block opens the file user has inputted and makes the string "File_contents" set to the file's contecnts
          fp = fopen(argv[2],"r");
          char *file_contents;
          long input_file_size;
          fseek(fp, 0, SEEK_END);
          input_file_size = ftell(fp);
          rewind(fp);
          file_contents = malloc((input_file_size + 1) * (sizeof(char)));
          fread(file_contents, sizeof(char), input_file_size, fp);
          fclose(fp);
          file_contents[input_file_size] = 0;
  
          char *word, *words[strlen(file_contents)/2+1];
          int i, n;
  
          for(i=0;file_contents[i];i++){
              file_contents[i]=tolower(file_contents[i]); //Converts all words to lower case
          }
  
          i=0;
          word = strtok(file_contents, " ,.-:;?!"); //Chars which signal end of word
  
          while(word != NULL) {
              words[i++] = word;
              word = strtok(NULL, " ,.-:;?!");
          }
  
          n = i;
  
          qsort(words, n, sizeof(*words), insert);
  
          for(i=0; i&lt;n; ++i){
              print(words[i],i);
              printf("%s\n", words[i]);
          }
          empty(words);
          fclose(fp); // Closes open file
      }
      return 0;
  }
  </code></pre>
  
  <p>And the following is the error I'm getting:</p>
  
  <p><strong>* glibc detected *</strong> concordance: double free or corruption (!prev): 0x0000000001060f010</p>
  
  <p>Not sure what could be causing this error to happen. Any help on this would be great though.</p>