scripting program (variables)

This is a discussion on scripting program (variables) within the C Programming forums, part of the General Programming Boards category; I'm writing a simple scripting program (so far, it can 'print'), but can't think of a good way to store ...

  1. #1
    Registered User kinghajj's Avatar
    Join Date
    Jun 2003
    Posts
    218

    scripting program (variables)

    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.

  2. #2
    Registered User Codeplug's Avatar
    Join Date
    Mar 2003
    Posts
    4,676
    Binary tree comes to mind.

    gg

  3. #3
    Registered User kinghajj's Avatar
    Join Date
    Jun 2003
    Posts
    218
    ... binary ... tree??

    can u elaborate on that thought, plz?

  4. #4
    Registered User Codeplug's Avatar
    Join Date
    Mar 2003
    Posts
    4,676
    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

  5. #5
    Registered User kinghajj's Avatar
    Join Date
    Jun 2003
    Posts
    218
    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...)

  6. #6
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,796
    >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".
    My best code is written with the delete key.

  7. #7
    Registered User kinghajj's Avatar
    Join Date
    Jun 2003
    Posts
    218
    ...hash table? I'll google it. Thx.

  8. #8
    Registered User kinghajj's Avatar
    Join Date
    Jun 2003
    Posts
    218
    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?

  9. #9
    End Of Line Hammer's Avatar
    Join Date
    Apr 2002
    Posts
    6,231
    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?
    Read through this to find your answers and more
    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
    When all else fails, read the instructions.
    If you're posting code, use code tags: [code] /* insert code here */ [/code]

  10. #10
    Registered User kinghajj's Avatar
    Join Date
    Jun 2003
    Posts
    218
    OK. I found a way. Phobos (a D lib) has a toInt function.

  11. #11
    End Of Line Hammer's Avatar
    Join Date
    Apr 2002
    Posts
    6,231
    If you want to learn to write portable code, use a standard conversion function as mentioned in the FAQ. Your choice...
    When all else fails, read the instructions.
    If you're posting code, use code tags: [code] /* insert code here */ [/code]

  12. #12
    Registered User kinghajj's Avatar
    Join Date
    Jun 2003
    Posts
    218
    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);
    Last edited by kinghajj; 01-06-2004 at 07:15 PM.

  13. #13
    Registered User kinghajj's Avatar
    Join Date
    Jun 2003
    Posts
    218
    P.S. D IS portable! there is a Win32 and Linux version.

  14. #14
    Registered User kinghajj's Avatar
    Join Date
    Jun 2003
    Posts
    218

    New Problem

    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 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.

    the error I get is: "Error: Access Violation"

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 4
    Last Post: 03-07-2009, 08:07 AM
  2. Client-server system with input from separate program
    By robot-ic in forum Networking/Device Communication
    Replies: 3
    Last Post: 01-16-2009, 02:30 PM
  3. Craps Program with Local Variables
    By tigrfire in forum C Programming
    Replies: 12
    Last Post: 11-09-2005, 08:01 AM
  4. Dikumud
    By maxorator in forum C++ Programming
    Replies: 1
    Last Post: 10-01-2005, 06:39 AM
  5. My program, anyhelp
    By @licomb in forum C Programming
    Replies: 14
    Last Post: 08-14-2001, 10:04 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21