title: Merged files versus appending files in C
body: <p>Can someone please help explain the difference in C and how my file fails to merge, and appends instead? The background is I am on an online computer science class this summer which uses C language, all we are given is read the entire texbook (732 pages), and do 20 projects over the course of 8 weeks, with no actual instruction, lecture, slides, or explanations. Please explain it so I can learn as I need to actually understand these terms to be better and progress in my Electrical Engineering program. I have contacted my professor for help but the answers are always short and uninformative, and you guys have provided so much more quality feedback to date. Also I do get that he is right and it was appended and not merged, but any feedback how i could of rectified this will help as well. Thank you again!</p>
  
  <pre><code>#include &lt;stdio.h&gt;
  #include &lt;stdlib.h&gt;
  
  FILE *inptr1, *inptr2, *outptr;
  
  int main()
  {
     char c; 
     char file1[30], file2[30], file3[30];
  
     printf("Enter the first files name\n");
     gets(file1);
  
     printf("Enter the second files name\n");
     gets(file2);
  
     printf("Enter the file name that will store the data from the other two files\n");
     gets(file3);
  
     inptr1 = fopen("C:\\Users\\Eric\\Desktop\\file1.txt","r");
     inptr2 = fopen("C:\\Users\\Eric\\Desktop\\file2.txt","r");
  
        if( inptr1 == NULL || inptr2 == NULL )
        {
          perror("Error ");
          printf("Press any key to exit!\n");
          exit(1);
        }
  
    outptr = fopen("C:\\Users\\Eric\\Desktop\\file3.txt","w");
  
        if( outptr == NULL )
        {
          perror("Error ");
          printf("Press any key to exit!\n");
          exit(1);
        }
  
      while( ( c = fgetc(inptr1) ) != EOF )
      fputc(c,outptr);
  
      while( ( c = fgetc(inptr2) ) != EOF )
      fputc(c,outptr);
  
    printf("The two files were sucessfully merged into %s \n",file3);
  
  fclose(inptr1);
  fclose(inptr2);
  fclose(outptr);
  
  return 0;
  }
  </code></pre>
  
  <p>Page 611 #5 Write a complete C program. Use the two files provided. Your program should not assume that you know which file is shorter.</p>
  
  <p>5) Write a function to merge two sorted files of names and write the names to a
  new file.</p>
  
  <p>Was the only direction I was given as far as to what the program was supposed to do.</p>
  
  <p>and this was the feedback i received, "Did you look at the resulting file?The girls names are all at the bottom. You were to merge the files,not append the files."</p>
  
  <p>Thank you again in advance for your valuable feedback as it has taught me so much to date.</p>