Skip to content

Instantly share code, notes, and snippets.

@zacbrown
Created January 5, 2010 01:02
Show Gist options
  • Save zacbrown/269051 to your computer and use it in GitHub Desktop.
Save zacbrown/269051 to your computer and use it in GitHub Desktop.
#include <stdio.h>
#include <string.h>
struct test {
int a;
int b;
int* c;
};
void main()
{
struct test blah;
blah.a = 5;
blah.b = 3;
blah.c = &blah.a;
printf("blah.a: %d | blah.c: 0x%08x | *blah.c: %d\n", blah.a, blah.c,*blah.c);
FILE *f = fopen("test.bin", "wb");
fwrite(&blah, 1, sizeof(struct test), f);
fclose(f);
memset(&blah, 0, sizeof(struct test));
struct test bloop;
f = fopen("test.bin", "rb");
fread(&bloop, 1, sizeof(struct test), f);
fclose(f);
printf("bloop.a: %d | bloop.c: 0x%08x | *bloop.c: %d\n", bloop.a, bloop.c, *bloop.c);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment