title: Reading binary integers from a file in C
body: <p>All night I have been looking for answers for this &amp; haven't slept, yet, I can't make it work...
  I have a binary file and I want to read it and take the value of each integer...
  Here is some code:</p>
  
  <pre><code>FILE *f;
  char ch;
  char t1[3];
  int l, c, grayScale, i, j;
  int p =0;
  
  
  f = fopen(pgm, "rb");
  
  (...)
  
  c = 0;
  l = 0;
  
  
  fscanf(f, "%d", &amp;c);
  
  fscanf(f, "%d", &amp;l);
  
  fscanf(f, "%d", &amp;grayScale);
  
  
  A = alocar_memoria_matriz(l,c);
  
  for(i = 0; i&lt;l; i++){
      for(j=0; j&lt;c; j++){
          if(fread(&amp;p,sizeof(int),1,f) !=1){
               fprintf(stderr, "\nError!\n");
               fclose(f);
               free_memoria_matriz(A,l);
               return NULL;
          }else if(p&gt;grayScale|| p&lt;0){
              fprintf(stderr, "\nError!\n");
              fclose(f);
              free_memoria_matriz(A,l);
              return NULL;
          }else{
          A[i][j] = (tdf_elemento) p;
  
      }
  }
  }
  </code></pre>
  
  <p>I did some <code>printf</code> of that p (with %d and %i) and I get values like -1161602550, 1213357911, 994462027...
  I really don't know what's going on, I also tried to change p for char[5] but didn't work so far...
  Thank you in advance...</p>