Posted By: SomebodyNew
Strings and Arrays - 09/15/09 08:13
Hello there,
I'm trying to construct the name of an array out of several Strings using str_cat . And then use the resulting string (the name of the array) to modify the array's values.
For Example:
Now I use the following function
But... it doesn't work. When I check for the value of test[3] it gives me a really huge number (90688).
The problem appears to be in the last line. It appears that the string "first_half" is not recognized as an array.
I'm stuck here and even after checking the manual I don't know how to work around this. What did I miss?
Any help is appreciated.
I'm trying to construct the name of an array out of several Strings using str_cat . And then use the resulting string (the name of the array) to modify the array's values.
For Example:
Code:
var probe_1[4] = { 1, 1, 1, 1}; var probe_2[4] = { 2, 2, 2, 2}; var probe_3[4] = { 3, 3, 3, 3}; var test[4] = { 0, 0, 0, 0}; STRING* first_half = "probe_"; STRING* number; STRING* second_half = "[3]";
Now I use the following function
Code:
function main() { str_cpy(number, "1"); str_cat(first_half, number); // "probe_" + "1" str_cat(first_half, second_half); // "probe_1" + "[3]" test[3] = first_half; }
But... it doesn't work. When I check for the value of test[3] it gives me a really huge number (90688).
The problem appears to be in the last line. It appears that the string "first_half" is not recognized as an array.
I'm stuck here and even after checking the manual I don't know how to work around this. What did I miss?
Any help is appreciated.