Sat Nov 08, 2008 1:28 am
struct Data
{
int nInt1;
int nInt2;
char czString[32];
};
FILE* pFile = fopen("filename.bin", "wb");
Data data;
// do stuff
fwrite(&data, sizeof(data), 1, pFile);
const int INT_SIZE = 4;
const int STRING_LENGTH = 32;
struct Data
{
int nInt1;
int nInt2;
char czString[STRING_LENGTH];
};
fwrite(&data.nInt1, INT_SIZE, 1, pFile);
fwrite(&data.nInt2, INT_SIZE, 1, pFile);
fwrite(&data.czString, 1, STRING_LENGTH, pFile);
Sat Nov 08, 2008 1:35 am
#include <stdio.h>
#include <limits.h>
int main(void)
{
unsigned long long i = 1234567890;
unsigned char c[4];
printf("Your integers are %i bits\n", CHAR_BIT *
sizeof(i));
c[0] = i & 0xff; /* least significant byte */
c[1] = (i & 0xff00) >> 8;
c[2] = (i & 0xff0000) >> 16;
c[3] = (i & 0xff000000) >> 24;
printf("0x%08x == ", i);
printf("0x%02x%02x%02x%02x", c[3], c[2], c[1], c[0]);
return 0;
}
Codemiles.com is a participant in the Amazon Services LLC Associates Program, an affiliate advertising program designed to provide a means for sites to earn advertising fees by advertising and linking to Amazon.com
Powered by phpBB © phpBB Group.