title: How do I read hex numbers into an unsigned int in C
body: <p>I'm wanting to read hex numbers from a text file into an unsigned integer so that I can execute Machine instructions.  It's just a simulation type thing that looks inside the text file and according to the values and its corresponding instruction outputs the new values in the registers.</p>
  
  <p>For example, the instructions would be:</p>
  
  <ul>
  <li>1RXY -> Save register R with value in
  memory address XY</li>
  <li>2RXY -> Save register R with value XY</li>
  <li>BRXY -> Jump to register R if xy is
  this and that etc..</li>
  <li>ARXY -> AND register R with value at
  memory address XY</li>
  </ul>
  
  <p>The text file contains something like this each in a new line. (in hexidecimal)</p>
  
  <ul>
  <li>120F</li>
  <li>B007</li>
  <li>290B</li>
  </ul>
  
  <p>My problem is copying each individual instruction into an unsigned integer...how do I do this?</p>
  
  <pre><code>#include &lt;stdio.h&gt;
  int main(){
      FILE *f;
      unsigned int num[80];
  
      f=fopen("values.txt","r");
      if (f==NULL){
          printf("file doesnt exist?!");
      }
  
      int i=0;
      while (fscanf(f,"%x",num[i]) != EOF){
          fscanf(f,"%x",num[i]);
          i++;
      }
      fclose(f);
      printf("%x",num[0]);
  }
  </code></pre>