xerof:
Right, so I'm using Webduino, which sets the variables (name/value), so name would contain the variable name, and value would contain the value I want the variable to be, but how do I set the Variable.
in PHP, I would do as such (Even though this isn't PHP, PHP is my strong point) ${$name} = $value; (So, This would take the variable name, and set the variable within the variable name (make sense? ))
I know I could do it long winded for each variable using a case on the name variable so example:
int variable_A = 0;
int variable_B = 1;
if (name == "variable_A") { variable_A = value; }
else if (name == "variable_B") { variable_B = value; }
Where really, I want to be doing name=value, but name being what ever the contents of name being (so either variable_A or variable B)
So in other words, you want to convert a string received over ethernet into a variable name?
If you're intent on NOT doing it with if/else statements, then you can use a lookup table and to put your variables into an array. Example:
int myVars[2] = { myVar1, myVar2 };
char hashTable[2][8] = { "myVar1", "myVar2" };
You then would loop through your lookup table, using strcmp() to see if your string matches the indexed value. If it does, take the index and use that for your myVars array.
It isn't really worth doing for only a couple variables, but the more variables you add, the more memory you use. Since we're working with a limited amount of memory, there are rarely any circumstances that warrant using this on a micro.