Thread: Dynamically create Identifiers?

  1. #1
    Registered User
    Join Date
    Dec 2006

    Question Dynamically create Identifiers?

    I'm working on a little program to read mathematical expressions, solve the equations and print out the answers.

    The problem is that it has to support variables.


    a+2 = 3

    and in the future, while running the program, I may use the value of 'a' ,that's supposed to be calculated by the program from the expression above, to find the value of yet another variable ('b').


    a+b = 5

    I've started to implement the program, but I can't figure out how to dynamically create identifiers with the names of the variables from the equations.

    Does anyone know how I can do this?

  2. #2
    Frequently Quite Prolix dwks's Avatar
    Join Date
    Apr 2005
    Sure -- you could have an array like the following
    int variable[26];  /* For variables 'A' - 'Z' (case insensitive) */
    Or a data structure like this
    struct variable_t {
        const char *name;
        double value;
    and then an ordinary array, a dynamically allocated array, or some other data structure.

    Seek and ye shall find. quaere et invenies.

    "Simplicity does not precede complexity, but follows it." -- Alan Perlis
    "Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
    "The only real mistake is the one from which we learn nothing." -- John Powell

    Other boards: DaniWeb, TPS
    Unofficial Wiki FAQ:

    My website:
    Projects: codeform, xuni, atlantis, nort, etc.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Create a file from c++ program
    By Dan17 in forum C++ Programming
    Replies: 2
    Last Post: 05-08-2006, 04:25 PM
  2. A question about dynamically creating an array of objects
    By edd1986 in forum C++ Programming
    Replies: 3
    Last Post: 03-19-2006, 12:30 PM
  3. Button handler
    By Nephiroth in forum Windows Programming
    Replies: 8
    Last Post: 03-12-2006, 06:23 AM
  4. How to create a file association program?
    By eShain in forum Windows Programming
    Replies: 1
    Last Post: 03-06-2006, 12:15 PM
  5. How to Create reference to an array in C++
    By shiv_tech_quest in forum C++ Programming
    Replies: 2
    Last Post: 12-20-2002, 10:01 AM