Hey there,
I'm having an issue with writing uint32_t values to file and then reading them back.
Code:
//My code to write the value is as follows,
//eklen = 128
FILE* pFilOutput = open_memstream(pChrOutputBuffer, &pSizTotalSize);
uint32_t eklen_n = htonl(eklen);
if (fwrite(&eklen_n, sizeof(uint32_t), 1, pFilOutput) != 1) {
//Failed to write data
}
//My code to read the value back again is as follows,
FILE* pFilInput = fmemopen(pChrData, strlen(pChrData), "r");
uint32_t eklen_n;
fread(&eklen_n, sizeof(eklen_n), 1, pFilInput);
int eklen = ntohl(eklen_n);
Wrote = -2147483648
Read 1344601458
---
I'm guessing I'm making a school boy error here but I just can't see it. I thought maybe I needed to specify "b" in the fmemopen mode parameter but that didn't help and on further reading I assume it's binary by default anyway.
Any ideas what I'm doing wrong? Many thanks in advance for any help!
Nick.