All pastes #822606 Raw Edit

Untitled

public text v1 · immutable
·published 2007-12-18 20:50 UTC
rendered paste body
serialise.c:
#include <stdio.h>
#include <strings.h>
#include <stdlib.h>

struct test { int asd; int asd2;};
int main(){
        struct test *seri = malloc(sizeof(struct test));
        seri->asd = 3;
        seri->asd2 = 5;
        FILE *f_ptr = fopen("1serial.txt", "w+");
        fwrite(seri, sizeof(struct test), 1, f_ptr);
        sync();
        struct test *seri2 = malloc(sizeof(struct test));
        seri2->asd = 1; seri2->asd2 = 1;
        fread(seri2, sizeof(struct test), 1, f_ptr);
        fclose(f_ptr);
        printf("%d should = %d\n", seri2->asd, seri->asd);
}

1serial.txt:
`hexdump -d 1serial.txt`

0000000   00003   00000   00005   00000                                
0000008