I can't seem to find the problem with this program. I've been looking over it for a long time, and i just can't find the error. It comes up with around 8 errors, but i think only one is causing the rest or the errors.
Code:
#include <stdlib.h>
#include <stdio.h>
struct tree
{
char info;
struct tree *left;
struct tree *right;
};
struct tree *root;
struct tree *stree(struct tree *root, struct tree *r, char info);
void print_tree(struct tree *root, int 1);
void main(void)
{
char s[80];
root = NULL;
do
{
printf("Enter a letter: ");
gets(s);
if(!root) root = stree(root, root, *s);
else stree(root, root, *s);
}while(*s);
print_tree(root, NULL);
}
struct tree *stree(struct tree *root, struct tree *r, char info)
{
if(!r)
{
r = (struct tree *) malloc(sizeof(struct tree));
if(!r)
{
printf("Out of Memory\n");
exit(0);
}
r->left = NULL;
r->right = NULL;
r->info = info;
if(!root) return r;
if(info<root->info) root->left = r;
else root->right = r;
return r;
}
if(info<r->info) stree(r, r->left, info);
else
stree(r, r->right, info);
}
void print_tree(struct tree *r, int 1)
{
int i;
if (!r)return;
print_tree(r->right, 1+1);
for(i=0; i<1; ++i) printf(" ");
printf("%c\n", r->info);
print_tree(r->left, 1+1);
}