Re: C Program: FUNCTION failed to return ARRAY values
Originally posted by sendtovasu
in the main function ur calling func('2')
instead u just use in main function use func(2)
maybe I really should read posts better
yes, i didn't look there properly the first time, actually passing 50 (ASCII code of '2') instead of 2 there.
I didn't look for s being static either before but you still cannot access it's data outside the function scope:
Static variables are created and initialized once, on the first call to the function. Subsequent calls to the function do not recreate or re-initialize the static variable. When the function terminates, the variable still exists on the _DATA segment, but cannot be accessed by outside functions.
Additionally the line
if (!s)strcpy(s, "Unknown");
is very dangerous as s is undefined when c<0 or c>10 and NOT neccesarily NULL.
edit: or well, static variables get initialized with 0 so this should work again, *sigh*, what did I write above?