1
0
mirror of https://github.com/fumiama/simple-kanban.git synced 2026-07-01 16:40:26 +08:00

优化代码架构

This commit is contained in:
fumiama
2021-05-18 13:01:59 +08:00
parent 42993de040
commit a402230dc5
3 changed files with 21 additions and 19 deletions

View File

@@ -1,13 +1,8 @@
#include <stdio.h>
#include <string.h>
#include "config.h"
#include "simple-protobuf/simple_protobuf.h"
struct CONFIG {
char pwd[64]; //password
char sps[64]; //set password
};
typedef struct CONFIG CONFIG;
CONFIG cfg;
int main() {
@@ -19,13 +14,14 @@ int main() {
FILE* fp = fopen("cfg.sp", "wb");
if(fp) {
set_pb(fp, types_len, sizeof(CONFIG), &cfg);
memset(&cfg, 0, sizeof(CONFIG));
fclose(fp);
puts("Write file succeed.");
puts("Config is saved to cfg.sp.");
fp = NULL;
puts("Check config...");
fp = fopen("cfg.sp", "rb");
if(fp) {
SIMPLE_PB* spb = get_pb(fp);
memset(&cfg, 0, sizeof(CONFIG));
memcpy(&cfg, spb->target, sizeof(CONFIG));
printf("set pwd: %s, sps: %s\n", cfg.pwd, cfg.sps);
} else perror("[SPB]");