From 171858b55040683807bd4f12eef249632e74bdf2 Mon Sep 17 00:00:00 2001 From: matze Date: Sat, 28 Jul 2007 20:47:04 +0000 Subject: [PATCH] load_state git-svn-id: https://shell.noname-ev.de/svn/kasse/c128@24 af93e077-1a23-4f1e-9cbe-9382a9d578f5 --- config.c | 26 ++++++++++++++++++++++++-- 1 file changed, 24 insertions(+), 2 deletions(-) diff --git a/config.c b/config.c index 1d23f76..5dbd328 100644 --- a/config.c +++ b/config.c @@ -14,6 +14,7 @@ struct credits_t credits[MAX_CREDIT_ITEMS+1]; #ifdef REAL_DATA void load_config(); + void load_items(){ FILE* f; char line[80]; @@ -29,9 +30,30 @@ void load_items(){ } +/** + * must be called after load_items() + */ void load_state(){ - status[0].times_sold=23; - status[1].times_sold=42; + FILE* f; + char line[80]; + char * sep; + char i, j; + f = fopen("state", "r"); + if (f==NULL){ + printf("cannot open state\n"); + return; + } + while (!feof(f)) { + fgets(line, 79, f); + sep = strchr(line, '='); + *(line + (sep-line)) = 0; + for (i=0; i< MAX_ITEMS; i++) { + if (strcmp(line, status[i].item_name)==0) { + status[i].times_sold = atoi(sep+1); + break; + } + } + } } void save_state(){} -- 2.39.5