mirror of
https://github.com/fumiama/simple-dict.git
synced 2026-06-22 20:21:04 +08:00
优化代码结构
This commit is contained in:
10
cfgwriter.c
10
cfgwriter.c
@@ -3,17 +3,17 @@
|
||||
#include <simple_protobuf.h>
|
||||
#include "config.h"
|
||||
|
||||
CONFIG cfg;
|
||||
config_t cfg;
|
||||
|
||||
int main() {
|
||||
printf("Enter a password: ");
|
||||
scanf("%s", cfg.pwd);
|
||||
printf("Enter a set password: ");
|
||||
scanf("%s", cfg.sps);
|
||||
uint32_t* types_len = align_struct(sizeof(CONFIG), 2, cfg.pwd, cfg.sps);
|
||||
uint32_t* types_len = align_struct(sizeof(config_t), 2, cfg.pwd, cfg.sps);
|
||||
FILE* fp = fopen("cfg.sp", "wb");
|
||||
if(fp) {
|
||||
set_pb(fp, types_len, sizeof(CONFIG), &cfg);
|
||||
set_pb(fp, types_len, sizeof(config_t), &cfg);
|
||||
fclose(fp);
|
||||
puts("Config is saved to cfg.sp.");
|
||||
fp = NULL;
|
||||
@@ -21,8 +21,8 @@ int main() {
|
||||
fp = fopen("cfg.sp", "rb");
|
||||
if(fp) {
|
||||
SIMPLE_PB* spb = get_pb(fp);
|
||||
memset(&cfg, 0, sizeof(CONFIG));
|
||||
memcpy(&cfg, spb->target, sizeof(CONFIG));
|
||||
memset(&cfg, 0, sizeof(config_t));
|
||||
memcpy(&cfg, spb->target, sizeof(config_t));
|
||||
printf("set pwd: %s, sps: %s\n", cfg.pwd, cfg.sps);
|
||||
} else perror("[SPB]");
|
||||
} else perror("[SPB]");
|
||||
|
||||
Reference in New Issue
Block a user