I'm writing a simple scripting program (so far, it can 'print'), but can't think of a good way to store variables that the user creates in the script. does anybody have any idead? thx.
Printable View
I'm writing a simple scripting program (so far, it can 'print'), but can't think of a good way to store variables that the user creates in the script. does anybody have any idead? thx.
Binary tree comes to mind.
gg
... binary ... tree??
can u elaborate on that thought, plz?
Hmmm, a linked list might be a better to start off with (search the board, been covered alot).
Each node in the list may contain the variable name and its current value.
gg
OK! Link-lists are in my book.... that may be a little hard to implement... but I can see how it can be done. thx. (though, arrays might be a problem in the future...)
>Binary tree comes to mind.
>a linked list might be a better to start off with
Actually, a hash table would be better suited for this purpose, and it has the advantage of being simpler to understand than a linked list or binary tree for a newcomer.
>... binary ... tree??
>can u elaborate on that thought, plz?
Check the General Discussion board. I posted an extensive (if incomplete at the time) tutorial on binary search trees under the thread "Request for Comment".
...hash table? I'll google it. Thx.
got it to work.
I have 2 BIG arrays (1000 elements), and keep the name of the variable in 1, and the value in the other. I also have an int that holds the value of the next empty element.
I only have char, though.
any thoughts on how to read text and convert it to an interger?
Read through this to find your answers and moreQuote:
Originally posted by kinghajj
got it to work.
I have 2 BIG arrays (1000 elements), and keep the name of the variable in 1, and the value in the other. I also have an int that holds the value of the next empty element.
I only have char, though.
any thoughts on how to read text and convert it to an interger?
http://faq.cprogramming.com/cgi-bin/smartfaq.cgi
Specifically:
http://faq.cprogramming.com/cgi-bin/...&id=1043284385
http://faq.cprogramming.com/cgi-bin/...&id=1073086407
OK. I found a way. Phobos (a D lib) has a toInt function. :D
If you want to learn to write portable code, use a standard conversion function as mentioned in the FAQ. Your choice...
then what's the prototype for atoi()?
EDIT
nevermind. it doesn't work (in D).
but I still found the prototype:
int atoi(const char *nptr);
P.S. D IS portable! there is a Win32 and Linux version.
the last time the test script uses this I get an error. it's always the last one, no matter what I tell it to put.Code:void _putchar()
{
int i = 0;
int ii = 0;
char var_name[32];
while(buff[i] != ' ')
{
i++;
}
i++;
for(ii = 0; buff[i] != ' ' && buff[i] != '\n' && ii < var_name.size;i++,ii++)
{
var_name[ii] = buff[i];
}
for(i = 0;var_name[0 .. 32] != c_name[i][0 .. 32] && i < 1000;)
{
i++;
}
if(var_name[0 .. 32] == c_name[i][0 .. 32])
{
putchar(c_value[i]);
}
if(_bdebug)
{
printf("\nvar_name: %.*s\nc_name: %.*s\ni: %i",var_name,c_name[i],i);
}
nullify(var_name);
return;
}
the error I get is: "Error: Access Violation"