summaryrefslogtreecommitdiff
path: root/c-structs/read.c
blob: 758256f896b776ed0b076454c5427924dc20ea8e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
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;
}