summaryrefslogtreecommitdiff
path: root/c-structs/read.c
diff options
context:
space:
mode:
Diffstat (limited to 'c-structs/read.c')
-rw-r--r--c-structs/read.c24
1 files changed, 24 insertions, 0 deletions
diff --git a/c-structs/read.c b/c-structs/read.c
new file mode 100644
index 0000000..b67974f
--- /dev/null
+++ b/c-structs/read.c
@@ -0,0 +1,24 @@
+#include <stdio.h>
+
+#include "struct.h"
+
+int main(void) {
+ printf("Read struct\n");
+
+ Character ch;
+
+ FILE* file = fopen("character.dat", "rb");
+ if (file == NULL) {
+ perror("Error opening file");
+ return 1;
+ }
+
+ fread(&ch, sizeof(Character), 1, file);
+ fclose(file);
+
+ printf("Name: %s\n", ch.name);
+ printf("Health: %d\n", ch.health);
+ printf("Damage: %.1f\n", ch.damage);
+
+ return 0;
+}