summaryrefslogtreecommitdiff
path: root/c-structs/write.c
blob: e83531adfcb66d35beb182740fcd3b06b0e07949 (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
25
#include <stdio.h>
#include <string.h>

#include "struct.h"

int main(void) {
    printf("Write struct\n");

    Character ch;

    strcpy(ch.name, "John Doe");
    ch.health = 30;
    ch.damage = 5.9;

    FILE* file = fopen("character.dat", "wb");
    if (file == NULL) {
        perror("Error opening file");
        return 1;
    }

    fwrite(&ch, sizeof(Character), 1, file);
    fclose(file);

    return 0;
}