title: Merge 2 files and sort them
body: <p>I have 2 txt files where I have numbers > 0 and I have to combine and sort them. Also there cannot be 2 same values.</p>
  
  <p>Here are values of files.
  File1:</p>
  
  <pre><code>1
  2
  3
  4
  5
  6
  7
  </code></pre>
  
  <p>File2:</p>
  
  <pre><code>1
  3
  6
  8
  10
  </code></pre>
  
  <p>The output should look like this:</p>
  
  <pre><code>1
  2
  3
  4
  5
  6
  7
  8
  10
  </code></pre>
  
  <p>The code which I have so far:</p>
  
  <pre><code>#include &lt;stdio.h&gt;
  #include &lt;stdlib.h&gt;
  
  int main()
  {
      FILE *fr1,*fr2;
      int fst, snd, p[256], i=0, n=0;
      bool f1=true,f2=true;
  
      fr1 = fopen("txt/cisla.txt","r");
      fr2 = fopen("txt/cisla2.txt","r");
  
      while(feof(fr1) == 0 &amp;&amp; feof(fr2) == 0)
      {
  
          if (f1) fscanf(fr1, "%d", &amp;fst);
          if (f2) fscanf(fr2, "%d", &amp;snd);
  
          printf("%d - %d\n", fst, snd);
  
          if (fst == snd) 
          {
              f1 = true;
              f2 = true;
              p[i] = fst;
          }   else if (fst &gt; snd)
          {
              p[i] = snd;
              f1 = false; 
              f2 = true;
          }   else
          {
              f2 = false;
              f1 = true;
              p[i] = fst;
          }
  
          i++;
  
      }
  
      fclose(fr1);
      fclose(fr2);
  
      printf("\n\n\n");
  
      for(int j = 0; j &lt; i; j++)
      {
              printf("%d\n", p[j]);
      }
  
      return 0;
  
  }
  </code></pre>
  
  <p>The result of this is:</p>
  
  <pre><code>1 - 1
  2 - 3
  3 - 3
  4 - 6
  5 - 6
  6 - 6
  7 - 8
  
  
  1
  2
  3
  4
  5
  6
  7
  </code></pre>
  
  <p>The bottom part is the array. At top I am writing the values which are read. The thing is it seems to stop at the end of the first file but I want it to continue the second one even if the first one is at the end</p>