mirror of
https://github.com/fumiama/simple-dict.git
synced 2026-06-25 06:08:06 +08:00
引入全新dict格式
This commit is contained in:
29
cfgwriter.c
Normal file
29
cfgwriter.c
Normal file
@@ -0,0 +1,29 @@
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <simple_protobuf.h>
|
||||
#include "config.h"
|
||||
|
||||
CONFIG 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);
|
||||
FILE* fp = fopen("cfg.sp", "wb");
|
||||
if(fp) {
|
||||
set_pb(fp, types_len, sizeof(CONFIG), &cfg);
|
||||
fclose(fp);
|
||||
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]");
|
||||
} else perror("[SPB]");
|
||||
}
|
||||
Reference in New Issue
Block a user