I am having problem executing this code i wrote for creating a binary tree.the code is compiling well but its stops running after taking the input of words.please help...
insert
Code:
#include<stdio.h>
#include<conio.h>
#include<string.h>
#include<stdlib.h>
#include<ctype.h>
#include<stddef.h>
#define MAX 100
struct tnode{
char *word;
int count;
struct tnode *left;
struct tnode *right;
};
struct tnode *additem(struct tnode *,char *);
void printtree(struct tnode *);
main()
{struct tnode *root,*p1;
char *p[10],words[10][MAX];
int i,n,k;
root=NULL;
for(i=0;i<10;i++)
{p[i]=words[i];
gets(p[i]);
}
root=additem(root,p[0]);
k=1;
while(k<10)
{if(isalpha(*(p[k]+0)))
{
p1=additem(root,p[k]);
}
}
printtree(root);
getch();
}
struct tnode *talloc(void);
struct tnode *additem(struct tnode *p,char *w)
{
int cond;
if(p==NULL)
{
p=talloc();
p->word=w;
p->count=1;
p->left=NULL;
p->right=NULL;
}
else if((cond=strcmp(p->word,w))==0)
p->count++;
else if(cond>0)
p->left=additem(p->left,w);
else
p->right=additem(p->right,w);
return p;
}
void printtree(struct tnode * tree) {
if(tree->left) printtree(tree->left);
printf("%4d %s\n",tree->count,tree->word);
if(tree->right) printtree(tree->right);
}
struct tnode *talloc(void)
{
return (struct tnode *)malloc(sizeof(struct tnode));
}