From fcec176008c68f13451559581aa1d1bb50b3d170 Mon Sep 17 00:00:00 2001 From: Logen Kain Date: Sun, 24 Jul 2016 17:41:45 -0700 Subject: [PATCH] c_lua_converge_optional_args: fixed pointers --- c_lua_converge_optional_args/fake.txt | 6 +++--- c_lua_converge_optional_args/main.c | 13 +++++++------ 2 files changed, 10 insertions(+), 9 deletions(-) diff --git a/c_lua_converge_optional_args/fake.txt b/c_lua_converge_optional_args/fake.txt index be5e8f3..ad64be0 100644 --- a/c_lua_converge_optional_args/fake.txt +++ b/c_lua_converge_optional_args/fake.txt @@ -1,3 +1,3 @@ -width = "Width" -heigt = "Height" -extra = "extra" +width = "Width line" +heigt = "Height line" +extra = "extra line" diff --git a/c_lua_converge_optional_args/main.c b/c_lua_converge_optional_args/main.c index 0c5b92d..ca1c42e 100644 --- a/c_lua_converge_optional_args/main.c +++ b/c_lua_converge_optional_args/main.c @@ -26,7 +26,7 @@ int main () void load(char *filename, int number_of_args, ...){ int i =1; - char test[100]; + char *test[number_of_args]; va_list opt_args; @@ -40,14 +40,15 @@ void load(char *filename, int number_of_args, ...){ for(i = 0; i < number_of_args; i++) { - strcpy(test, va_arg(opt_args, char*)); - lua_getglobal(L, test); + test[i] = va_arg(opt_args, char*); + lua_getglobal(L, test[i]); if (!lua_isstring(L, (i+1))){ - error(L, "%s Missing variable: %s%s\n",KRED, test, KNRM); + error(L, "%s Missing variable: %s%s\n",KRED, test[i], KNRM); + strcpy(test[i], " "); continue; } - strcpy(test, lua_tostring(L, (i+1) )); - printf("Is Test: %s\n", test); + strcpy(test[i], lua_tostring(L, (i+1) )); + //printf("Is Test: %s\n", test[i]); } va_end(opt_args);