title: Reading from files passed as command line arguements
body: <p>I am trying to parse a given textfile, but so far, my program does not seem to be reading properly.</p>
  
  <pre><code>#include &lt;stdio.h&gt;
  
  
  int main(int argc, char *argv[])
  {
      FILE *fr; //file pointer
      int buildingFloors = 1;
  
      printf("sanity check\n");  
  
      fr = fopen (argv[0], "r");
      fscanf(fr, "%d", &amp;buildingFloors );
  
      printf("%d\n", buildingFloors);
  
      fclose(fr);
  
      return 0;
  }
  </code></pre>
  
  <p>I compile the program and run it on my redhat linux machine with the following command:</p>
  
  <pre><code>./sjf file.text
  </code></pre>
  
  <p>file.text is a text document with a "4" as the first character. So I would expect my output to be</p>
  
  <pre><code>sanity check
  4
  </code></pre>
  
  <p>However, when I run my program I instead get</p>
  
  <pre><code>sanity check
  1
  </code></pre>
  
  <p>Which implies that fscanf didn't properly read in the first character -- 4. Do I have some syntax error that's preventing the expected code functionality? Am I supposed to scanf for a character, and then convert that to an int somehow?</p>