title: Reading from two different files and printing to third one
body: <p>I need to read from 2 different files and print words to third one, first i read from file1 and save first word to file third, then read from file2 and save first word from here to third file as second word and so on.. and also words from file1 have "+" at the start of the word and from file2 have "-". My problem is that code doesnt stop and is still working and printig to third file "."(lot of dots). thanks</p>
  
  <pre><code>#include&lt;stdio.h&gt;
  #include&lt;stdlib.h&gt;
  
  int main(){
      FILE *first, *second, *third;
      char ch[256],ch1[256],ch2;
      int i=1,count;
      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)
          {
          printf("error");
          exit(1);
          }
  
          while (fscanf(first, "%255s", ch) == 1)
          {
              count++;
          }
  
          while (fscanf(second, "%255s", ch) == 1)
          {
              count++;
          }
  
          printf("%d",count);
  
          for(i;i&lt;=count;i++)
          {
              if(i%2==1)
              {
                  fputc(plus,third);
                  ch2=fgetc(first);
                  while(ch2 != EOF || ch2 != ' ')
                      putc(ch2,third);
                      ch2=fgetc(first);
              }
              else if(i%2==0)
              {
                  fputc(minus,third);
                  ch2=fgetc(second);
                  while(ch2 != EOF || ch2 != ' ')
                      putc(ch2,third);
                      ch2=fgetc(second);
              }
                  fputc(space,third);         
          }
  
  
      fclose(first);
      fclose(second);
      fclose(third);
  
      return 0;
  }
  </code></pre>