subramanyeswari wrote:
I used fwrite and fread but it is not working.
(Un)fortunately It doesn't depend on fwrite and fread, my friend. The following works for me (error checking left as exercise)
int main()
{
{
BYTE bValue[]={2,4,8};
// Length of the array
int iLen = sizeof(bValue)/sizeof(bValue[0]);
// WRITE array
// open file for output in binary mode
FILE * fpo = fopen("foo.bin", "wb");
// store array length
fwrite(&iLen, sizeof(iLen), 1,fpo);
// store array elements
fwrite(bValue, sizeof(bValue), 1, fpo);
fclose(fpo);
}
{
BYTE * bValue;
// READ array
// open file for input in binary mode
FILE * fpi = fopen("foo.bin", "rb");
int iLen;
// read array length
fread(&iLen, sizeof(iLen), 1,fpi);
// read array elements
bValue = new BYTE[iLen];
fread(bValue, sizeof(BYTE), iLen, fpi);
fclose(fpi);
// use values
// ...
//Cleanup
delete [] bValue;
}
return 0;
}
:)
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong. -- Iain Clarke
[My articles]