title: File read behavior while reading file from C code
body: <p>I am trying to execute a simple code to read a file in which data is written from python script as int32 type</p>
  
  <pre><code># array_values is a numpy array
  array_values.astype('int32').tofile(filename + '.dat')
  </code></pre>
  
  <p>The c program to read it is as below:</p>
  
  <pre><code>#include &lt;iostream&gt;
  #include &lt;fstream&gt;
  typedef unsigned uint32_t;
  int main()
  {
           char* filename;
           FILE* f;
           uint32_t number;
           filename = "datfile.dat";
           f = fopen(filename, "rb");
           if (f == NULL){
                   printf("File NULL");
           }
           //fseek(f, SEEK_SET, 0);
  
           for (int i = 0; i &lt; 10; i++){
                   fread(&amp;number, 4, 1, f);
                   printf("%d   %08x \n", i, number);
           }
  
  
      return 0;
  }
  </code></pre>
  
  <p>The code above gives the following result:</p>
  
  <pre><code>0   01040000
  1   00260e7d
  2   0375016c
  3   07caf50c
  4   0dd90464
  5   f8e2f9ea
  6   076d0527
  7   00c61143
  8   113af1de
  9   fbb5038b
  </code></pre>
  
  <p>If I change the it to read 2 bytes</p>
  
  <pre><code>fread(&amp;number, 2, 1, f);
  </code></pre>
  
  <p>It gives the following output: ( and it is the expected and correct one )</p>
  
  <pre><code>0   00000000
  1   00000104
  2   00000e7d
  3   00000026
  4   0000016c
  5   00000375
  6   0000f50c
  7   000007ca
  8   00000464
  9   00000dd9
  </code></pre>
  
  <p>I fail to understand why int32 is not giving the correct result when 4 bytes are read.</p>
  
  <p>EDIT:</p>
  
  <p>Output after using numpy.swapbytes(True) to toggle between the big and little endian before saving data to the file and the output is much more messed up</p>
  
  <pre><code>0   00000000
  1   00000000
  2   00000000
  3   0000ffff
  4   00000000
  5   ffffffff
  6   00000000
  7   00000000
  8   0000ffff
  9   ffff0000
  </code></pre>