title: Why fscanf / scanf is changing the value of previously scanned variable on Ideone.com?
body: <p>I wrote a simple code on Ideone.com. The value of variable f is changing after execution of the command fscanf for taking the input string in next line.</p>
  
  <pre><code>#include &lt;stdio.h&gt;
  
  int main()
  {
      FILE* fp = stdin;
      int i=0, f,arr[3], count =0;
      char inp[3];
      for(i=0;i&lt;3;i++)
      {
          arr[i]=0;
      }
      fscanf(fp, "%d\n", &amp;f);
      printf("%d\n", f);
      for(i;i&lt;f;i++)
      {
          printf("%d\n", f);
          fscanf(fp , "%s\n", inp);
          printf("%d\n", f);
          if(inp[2]=='2')
              arr[1]++;
          else if(inp[0]=='1')
              arr[0]++;
          else
              arr[2]++;
      }
      printf("%d %d %d %d\n",f, arr[0], arr[1], arr[2]);
  return 0;
  }
  </code></pre>
  
  <p>The input I provided was</p>
  
  <pre><code>10
  3/4
  3/4
  3/4
  3/4
  3/4
  3/4
  3/4
  3/4
  3/4
  3/4
  </code></pre>
  
  <p>But the value of f is changing from 10 to 0 after the first scanf.</p>