title: In C: File Not Found Error When using readInputFile function for a second time on fclose()
body: <p>I am trying to read two different .txt files to compare them later in my code. For this project, I needed to dynamically allocate the files since I am not allowed a max character size. My function correctly gets the file information correctly on the first run, but it crashes with an error on the second run when reading the second input file. The Error being: Error: File Not Found. Any idea on what is causing it to fail during the second run? Thanks</p>
  
  <pre><code>int main(int argc, char *argv[])
  { 
      struct stat stringBuffer1; 
      struct stat stringBuffer2;
      stat(argv[1], &amp;stringBuffer1); 
      stat(argv[2], &amp;stringBuffer2); 
      FILE *textFile1 = NULL, *textFile2 = NULL, *outputFile = NULL; 
      textFile1=fopen(argv[1], "r");
      textFile2=fopen(argv[2], "r");
      char* fileString1;
      char* fileString2;
      printf("code before readInputFile");
      fileString1 = strdup(readInputFile(textFile1,stringBuffer1));
      fileString2 = strdup(readInputFile(textFile2,stringBuffer2));
  
  char* readInputFile(FILE* targetFile, struct stat stringBuffer)
  {       
      char *tempString=malloc(stringBuffer.st_size+1); 
      fread(tempString, 1, stringBuffer.st_size, targetFile); 
      fclose(targetFile); //Error happens here
      char* finalString = &amp;tempString[stringBuffer.st_size];
      tempString[stringBuffer.st_size]=0; // Setting 0-Byte
      strcpy(finalString,tempString);
      free(tempString);
      return finalString;
  }
  </code></pre>