Question: I am trying to read a binary tree into my program using the following function that i wrote.

```
void readTree(struct Dnode *root)
{
    struct Dnode *temp;
    struct Dnode *input;
    char initData;

    scanf(" %c",&initData);
    input=CreateNode(initData);

    if(initData==122){
        printf("Leaf\n");
        return;
    }
    else {
        root=input;
        temp=root;
        printf("going to left of %c\n",initData);
        readTree(root->lLink);
        printf("going to right of %c\n",initData);
        readTree(root->rLink);
    }
}

```

Everything is working fine except the fact that , in main the tree doesnt exist. Here is my main program:

```
int main()
{
    int n=0;
    struct Dnode *root=NULL;
    printf("Enter the tree as it asks. Enter z whenever there is no children :\n");
    readTree(root);
    printf("%c",root->data);
    printf("In main");
    return;

 }

```

The program suddenly crashes after inputting the tree.Please help me.

Answer: 
Support for string input:

```
std::map<std::string, std::function<void()>> le_mapo;
le_mapo["1"] = &function1;
le_mapo["2"] = &function2;
le_mapo["3"] = &function3;
le_mapo["Hihihi"] = &functionHihihi;

std::string input;
std::cin >> input;

auto check = le_mapo.find(input);

if (check != le_mapo.end()) 
{
    le_mapo[input](); //call function
}
else
{
    //not found
}

```

Too long to write? Prepare for storm!

```
#define BE_EVIL(map, function, x) map[ #x ] = & function ## x
//custom macro with predefined function name (here: just function)
#define BE_EVIL_FUN(map, x) BE_EVIL(map, function, x)
//same, with predefined map name
#define BE_EVIL_JUST_X(x) BE_EVIL_FUN(le_mapo, x)

```

And use:

```
//"connect" string to function
BE_EVIL(le_mapo, function, 1); //le_mapo[ "1" ] = & function1;

```
You can use the *polymorphism* concept (via virtual functions and inheritance).

Here is a very basic scheme:

```
#include <iostream>
#include <vector>

using namespace std;

class Obj
{
public:
    virtual void function() = 0;
};

class Obj1 : public Obj
{
public:
    virtual void function() {cout << "Function No. 1 was called!";}
};

class Obj2 : public Obj
{
public:
    virtual void function() {cout << "Function No. 2 was called!";}
};

class Obj3 : public Obj
{
public:
    virtual void function() {cout << "Function No. 3 was called!";}
};

int main()
{
    vector<Obj*> objects;
    objects.push_back(new Obj1);
    objects.push_back(new Obj2);
    objects.push_back(new Obj3);

    cout << "Which function do you want to call?";
    int whichFunction;
    cin >> whichFunction;
    if (1 <= whichFunction && whichFunction <= objects.size())
        objects[whichFunction-1]->function();

    for (auto object : objects)
        delete object;

    return 0;
}

```