diff options
| author | Mitja Felicijan <mitja.felicijan@gmail.com> | 2024-06-22 20:01:14 +0200 |
|---|---|---|
| committer | Mitja Felicijan <mitja.felicijan@gmail.com> | 2024-06-22 20:01:14 +0200 |
| commit | 134f855b537b714eb98bc1e6e1e4790b4d6491a3 (patch) | |
| tree | c1cc9d813decd8a135a699a023977e1fb095da0c /c-structs/read.c | |
| parent | d9b6fe0bd815da591d9d16efb187ddcfb2aba109 (diff) | |
| download | probe-134f855b537b714eb98bc1e6e1e4790b4d6491a3.tar.gz | |
Added writing and reading structs from files
Diffstat (limited to 'c-structs/read.c')
| -rw-r--r-- | c-structs/read.c | 24 |
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; +} |
