Created
May 31, 2015 07:43
-
-
Save nidev/31d905242f3acd6780ce to your computer and use it in GitHub Desktop.
The taste of raw struct
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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