From c2d7ed2e01c1f5aef5e5107de71bb3117e14ee0d Mon Sep 17 00:00:00 2001 From: cozis Date: Mon, 25 Apr 2022 15:30:30 +0200 Subject: [PATCH] fixed bug in example --- examples/simple.c | 32 +++++++++++++++++--------------- 1 file changed, 17 insertions(+), 15 deletions(-) diff --git a/examples/simple.c b/examples/simple.c index 50ee59e..1edcf3a 100644 --- a/examples/simple.c +++ b/examples/simple.c @@ -19,25 +19,27 @@ int main() // ..error? if(val == NULL) fprintf(stderr, "Failed to parse!\n"); - - char *name; - int age; - - // Now iterate over the fields to get the name - // and age. - xj_value *child = val->as_object; - while(child != NULL) + else { - if(!strcmp("name", child->key)) - name = child->as_string; - else - age = child->as_int; + char *name; + int age; - child = child->next; + // Now iterate over the fields to get the name + // and age. + xj_value *child = val->as_object; + while(child != NULL) + { + if(!strcmp("name", child->key)) + name = child->as_string; + else + age = child->as_int; + + child = child->next; + } + + printf("name: %s, age: %d\n", name, age); } - printf("name: %s, age: %d\n", name, age); - // Now free everything! xj_alloc_del(alloc); return 0;