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: 
```
switch(whichFunction) {
    case 1: function1(); break;
    case 2: function2(); break;
    case 3: function3(); break;
}

```
use pointer to function is a good thing: 

```
#include <iostream>
#include <string>
using namespace std;

void foo1(){cout << "Foo1 says hello!" << endl;}
void foo2(){cout << "Foo2 says hello!" << endl;}
void foo3(){cout << "Foo3 says hello!" << endl;}
void foo4(){cout << "Foo4 says hello!" << endl;}

int main()
{

    system("color 1f");

    int input;
    cout << "Which function you wanna call: ";
    cin >> input;
    cout << endl;

    void (*pFunc)() = NULL;

    switch(input)
    {
        case 1:
            pFunc = foo1;
        break;
        case 2:
            pFunc = foo2;
        break;
        case 3:
            pFunc = foo3;
        break;
        default:
            cout << "No function available!" << endl;
    }

    if(NULL != pFunc) //avoiding usage of a NULL ptr
        (*pFunc)();

    cout << endl << endl << endl;
    return 0;
}

```