title: Making program to stop reading from file if EOF and read only from other
body: <p>Only problem is that when one file is at EOF, program still writes - or +, just need to make some condition to make it just takes words from one file when other is at EOF. For example </p>
  
  <blockquote>
    <p><strong>prvy.txt:</strong> Ahojte nasi studenti ktori maju radi programovanie</p>
    
    <p><strong>druhy.txt:</strong> vsetci mili</p>
    
    <p><strong>treti.txt:</strong>
    +Ahojte -vsetci +nasi -mili +studenti +ktori +maju +radi +programovanie</p>
  </blockquote>
  
  <pre><code>#include&lt;stdio.h&gt;
  #include&lt;stdlib.h&gt;
  
  int main(){
      FILE *first, *second, *third;
      char ch[256],ch1[256];
      int i=1,count=0, ch2;
      char space = ' ';
      char minus = '-';
      char plus = '+';
  
      first=fopen("prvy.txt", "r");
      second=fopen("druhy.txt", "r");
      third=fopen("treti.txt", "w");
  
      if(first==NULL || second==NULL || third==NULL)
      {
          perror("error");
          exit(1);
      }
  
      while (fscanf(first, "%255s", ch) == 1)
      {
          count++;
      }
  
      while (fscanf(second, "%255s", ch) == 1)
      {
          count++;
      }
  
      printf("%d",count);
  
      rewind(first);
      rewind(second);
  
      for(i;i&lt;=count;i++)
      {
          if(i%2==1)
          {
              fputc(plus,third);
              ch2=fgetc(first);
              while(ch2 != EOF &amp;&amp; ch2 != ' ' &amp;&amp; ch2 != '\n') {
                  putc(ch2,third);
                  ch2=fgetc(first);
              }
          }
          else if(i%2==0)
          {
  
              fputc(minus,third);
              ch2=fgetc(second);
              while(ch2 != EOF &amp;&amp; ch2 != ' ' &amp;&amp; ch2 != '\n') {
                  putc(ch2,third);
                  ch2=fgetc(second);
              }
          }
          putc(space,third);
      }   
  
      fclose(first);
      fclose(second);
      fclose(third);
  
      return 0;
  }
  </code></pre>