I am learning binary search tree. Given below is the main function of a program to perform basic BST operations. The `option` variable chooses which operation to perform for `switch`

```
int main()
{
struct node* tree=NULL;
struct node* ptr=NULL;
struct node* ptrm=NULL;
int val;
int option;
do
{
    printf("\n1.Insert Node\n2.Preorder Traversal\n3.Postorder Traversal\n4.Inorder Traversal\n5.find_smallest_element\n6.find_largest_element\n7.Delete Element\n8.Total_nodes\n9.total_external_nodes\n10.total_internal_nodes\n11.Mirror image\n12.Exit\n");
    printf("\nEnter option");
    scanf("%d",&option);
    switch(option)
    {
        case 1:
            printf("\nEnter value to be inserted");
            scanf("%d",&val);
            tree=insert_element(&tree,val);
            printf("\n%d Inserted\n",val);
            break;
        case 2:
            preorder(&tree);
            break;
        case 3:
            postorder(&tree);
            break;
        case 4:
            inorder(&tree);
            break;
        case 5:
            ptr=find_smallest_element(&tree);
            printf("\nSmallest element:%d",ptr->data);
            break;
        case 6:
            ptr=find_largest_element(&tree);
            printf("\nLargest element:%d",ptr->data);
            break;
        case 7:
            printf("\nEnter value of element to be deleted");
            scanf("%d",&val);
            tree=delete_node(&tree,val);
            break;
        case 8:
            printf("\nTotal nodes%d",total_nodes(&tree));
            break;
        case 9:
            printf("\nTotal External nodes%d",total_external_nodes(&tree));
            break;
        case 10:
            printf("\nTotal Internal nodes%d",total_internal_nodes(&tree));
            break;
        case 11:
            ptrm=mirror_image(&tree);

    }
}while(option!=12);
return 0;

```

Everything works fine when i give int data as input for 'option'.However, when i give a char input the program goes into infinite loop and displays option list repeatedly.

Why does this happen?