.wav C++ data not outputting correctly
<p>So I know I have asked this question before, however, I am still stuck and before I can move on with my project. Basically, I'm trying to read in a .wav file, I have read in all of the required header information and then stored all the data inside a char array. This is all good, however, I then recast the data as an integer and try and output the data. </p>

<p>I have tested the data in MatLab, however, I get very different results:</p>

<p>Matlab -0.0078 </p>

<p>C++: 1031127695</p>

<p>Now these are very wrong results, and someone kindly from here said it's because I'm outputting it as an integer, however, I have tried pretty much every single data type and still get the wrong results. Someone has suggestion that it could be something to do with Endianness (http://en.wikipedia.org/wiki/Endianness) .. Does this seem logical?</p>

<p>Here is the code:</p>

<pre><code>bool Wav::readHeader(ifstream &amp;file)
{

file.read(this-&gt;chunkId,                                 4);
file.read(reinterpret_cast&lt;char*&gt;(&amp;this-&gt;chunkSize),     4);
file.read(this-&gt;format,                                  4);

file.read(this-&gt;formatId,                                4);
file.read(reinterpret_cast&lt;char*&gt;(&amp;this-&gt;formatSize),    4);
file.read(reinterpret_cast&lt;char*&gt;(&amp;this-&gt;format2),       2);
file.read(reinterpret_cast&lt;char*&gt;(&amp;this-&gt;numChannels),   2);
file.read(reinterpret_cast&lt;char*&gt;(&amp;this-&gt;sampleRate),    4);
file.read(reinterpret_cast&lt;char*&gt;(&amp;this-&gt;byteRate),      4);
file.read(reinterpret_cast&lt;char*&gt;(&amp;this-&gt;align),         2);
file.read(reinterpret_cast&lt;char*&gt;(&amp;this-&gt;bitsPerSample), 4);

char testing[4] = {0};
int testingSize = 0;

while(file.read(testing, 4) &amp;&amp; (testing[0] != 'd' ||
                                testing[1] != 'a' ||
                                testing[2] != 't' ||
                                testing[3] != 'a'))
{

file.read(reinterpret_cast&lt;char*&gt;(&amp;testingSize), 4);
file.seekg(testingSize, std::ios_base::cur);

  }

      this-&gt;dataId[0] = testing[0];
      this-&gt;dataId[1] = testing[1];
      this-&gt;dataId[2] = testing[2];
      this-&gt;dataId[3] = testing[3];
     file.read(reinterpret_cast&lt;char*&gt;(&amp;this-&gt;dataSize),     4);

     this-&gt;data = new char[this-&gt;dataSize];

     file.read(data,                     this-&gt;dataSize);

     unsigned int *te;

     te = reinterpret_cast&lt;int*&gt;(&amp;this-&gt;data);

     cout &lt;&lt; te[3];

     return true;
     }
</code></pre>

<p>Any help would be really appreciated. I hope I've given enough details.</p>

<p>Thank you. </p>
