title: Problem with file handling(beginner level)?
body: <p>The goal is to fill file <code>output.txt</code> with characters that are repeating one after another n or more times (n is an integer inputted from a keyboard).</p>
  
  <pre><code>#include &lt;stdio.h&gt;
  #include &lt;stdlib.h&gt;
  
  int main() {
      int c=0,d=0;
      int n;
      scanf("%d",&amp;n);
      FILE* ulaz=fopen("input.txt","r");
      if(ulaz==NULL) {
          printf("TRY AGAIN");
          return 1;
      }
      FILE* izlaz=fopen("output.txt","w");
      if(izlaz==NULL) {
          fclose(ulaz);
          printf("TRY AGAIN");
          return 2;
      }
      long pos;
      int br=1;
      do {
          c=fgetc(ulaz);
              if(c!=EOF) {
              do {
                  long pos=ftell(ulaz);
                  d=fgetc(ulaz);
                  if(c==d) {
                      br++;
                  }
              } while(d==c &amp;&amp; d!=EOF);
              int i=0;
              if(br&gt;=n) {
                  for(i=0;i&lt;n;i++) {
                      fputc(c,izlaz);
                  }
              }
              fseek(ulaz,pos,SEEK_SET);
              //is this line a problem
              br=1; }
      } while(c!=EOF);
      fclose(ulaz);
      fclose(izlaz);
  }
  </code></pre>