C++ File Operations
<p>As part of an assignment, I need to read data from a binary file which consists of <code>int</code>, <code>char</code> datatypes of data. This binary file is divided into records 96 bytes each. I am trying to reading these 96 bytes into a <code>char</code> buffer and then trying to split them according to info I have. But I am getting nothing when trying to get <code>int</code> values from the buffer. Can you help me in this?</p>

<pre><code>#include&lt;iostream&gt;
#include&lt;fstream&gt;
#include&lt;cstdio&gt;

using namespace std;

int main()
{
    char buffer[100];
    char *p;
    char temp[10];
    int val;
    fstream ifs,ofs;
    ifs.open("write.bin",ios::binary);
    if(ifs.read(buffer,96)) 
    {
        cout &lt;&lt; "READ" &lt;&lt; endl;
    }      
    p = buffer; 
    memcpy(temp,buffer,4);
    cout &lt;&lt; temp &lt;&lt; endl;
    val = atoi(temp); 
    cout &lt;&lt; val &lt;&lt; endl;
} 
</code></pre>

<p>I used <code>strncpy</code> also in place of <code>memcpy</code>.
The output is 0 for <code>val</code> and blank for <code>temp</code>.</p>
