Skip to content

Instantly share code, notes, and snippets.

@nidev
Created May 31, 2015 07:43
Show Gist options
  • Save nidev/31d905242f3acd6780ce to your computer and use it in GitHub Desktop.
Save nidev/31d905242f3acd6780ce to your computer and use it in GitHub Desktop.
The taste of raw struct
#include <stdio.h>
#include <stdlib.h>
#define TRUE 1
#define FALSE 0
typedef struct Node {
int val;
int set;
struct Node *next;
} Node;
int main(int argc, char *argv[]) {
FILE *fp = NULL;
Node node, node2;
node.set = TRUE;
node.val = 1;
node.next = &node2;
node2.val = 2;
node2.set = TRUE;
node2.next = NULL;
fp = fopen("output.raw", "wb");
if (fp == NULL) {
printf("Shit\n");
return -1;
}
Node *p = &node;
while (p != NULL) {
fwrite(p, sizeof(Node), 1, fp);
p = p->next;
}
fclose(fp);
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment