-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathinteractive_test.c
More file actions
45 lines (34 loc) · 962 Bytes
/
interactive_test.c
File metadata and controls
45 lines (34 loc) · 962 Bytes
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
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <intro.h>
typedef int32_t s32;
typedef struct {
s32 demo I(fallback 22);
char * message I(fallback "empty message");
} SaveData;
#include "interactive_test.c.intro"
void
get_input_line(char * o_buf, size_t buf_size) {
fgets(o_buf, buf_size, stdin);
char * nl = strchr(o_buf, '\n');
if (nl) *nl = '\0';
}
int
main() {
SaveData save;
bool from_file = intro_load_city_file(&save, ITYPE(SaveData), "save.cty");
if (!from_file) {
intro_fallback(&save, ITYPE(SaveData));
}
printf("Save file contents:\n");
intro_print(&save, ITYPE(SaveData), NULL);
if (from_file) free(save.message);
char new_message [128];
printf("\nEnter a new message: ");
get_input_line(new_message, sizeof new_message);
save.message = new_message;
save.demo++;
intro_create_city_file("save.cty", &save, ITYPE(SaveData));
return 0;
}