The main problem with your code is that you only have one node. A tree is a dynamic structure, which means you need to create nodes at run-time (using malloc), and add these into the tree at the appropriate place.
Have a look at this
Code:
#include <stdio.h>
#include <stdlib.h>
struct node {
char data;
struct node *left;
struct node *right;
};
void insert_node ( struct node **root, char data ) {
if ( *root == NULL ) {
// a new leaf is needed
struct node *newnode = malloc( sizeof( struct node ) );
newnode->data = data;
newnode->left = NULL;
newnode->right= NULL;
*root = newnode;
} else {
// decide which way to go
if ( data < (*root)->data ) {
insert_node( &(*root)->left, data );
} else {
insert_node( &(*root)->right, data );
}
}
}
void print_tree ( struct node *root ) {
if ( root == NULL ) return;
print_tree( root->left );
printf( "%c", root->data );
print_tree( root->right );
}
int main(void) {
struct node *tree = NULL; // an empty tree
// we pass a pointer to tree, so that it gets updated
// when a node is allocated.
// an alternative function call would be
// tree = insert_node( tree, 'a' );
// which would require some mods to the function
// but would remove the ** in the function prototype
// (if that's too confusing at the moment)
insert_node ( &tree, 'c' );
insert_node ( &tree, 'f' );
insert_node ( &tree, 'b' );
insert_node ( &tree, 'd' );
insert_node ( &tree, 'a' );
print_tree( tree );
return 0;
}