大姐们大哥们看以下我这个程序怎么了
那里有问题啊?
#include<stdio.h>
#include<string.h>
struct tree
{
char word[20];
int count;
int sign;
struct tree * parent;
struct tree * leftson;
struct tree * rightson;
};
int i=0;
struct tree *treeroot;
char preword[20];
char temp[20];
FILE *fp;
Get_word(FILE *fp)
{
char ch;
int i=0;
ch=fgetc(fp);
strcpy(preword,temp);
while(ch!=' '&&ch!='\n'&&ch!='\r'&&ch!='\t'&&ch!=','&&ch!='.'&&ch!='\"'&&ch!='\'') {
preword[i]= ch;
i++;
ch=fgetc(fp);
}
if(i==0) return 0;
printf("the getword is :%s\n",preword);
return 0;
}
Sis_word(char *preword,struct tree *nangua)
{
struct tree *p;
if(strcmp(preword,nangua->word)>0)
{
if(nangua->rightson!=NULL) Sis_word(preword,nangua->rightson);
else if(nangua->rightson==NULL)
{
p =(struct tree*)malloc(sizeof(struct tree));
strncpy(p->word, preword,20);
p->count = 1;
printf("i want to insert this new word at right:%s\n",preword);
printf("the p.word is:%s\n",p->word);
p->rightson = NULL;
p->leftson = NULL;
p->parent = nangua;
p->sign=0;
nangua->rightson=p;
strcpy(preword,temp);
printf("changed word*****%s\n",preword);
return 0;
}
}
else if(strcmp(preword,nangua->word)==0) nangua->count++;
else if(strcmp(preword,nangua->word)<0)
{
if(nangua->leftson!=NULL) Sis_word(preword,nangua->leftson);
else if(nangua->leftson==NULL)
{
p =(struct tree*)malloc(sizeof(struct tree));
strncpy(p->word,preword,20);
p->count = 1;
printf("i want to insert this new word at left:%s\n",preword);
printf("the p.word is:%s\n",p->word);
p->rightson = NULL;
p->leftson = NULL;
p->parent = nangua;
p->sign=0;
nangua->leftson =p;
strcpy(preword,temp);
printf("changed word*****%s\n",preword);
return 0;
}
}
}
visit(struct tree *treeroot)
{
if(treeroot->leftson!=NULL) visit(treeroot->leftson);
else if(treeroot->leftson==NULL&&treeroot->rightson!=NULL)
{
printf("%s***%d",treeroot->word,treeroot->count);
treeroot->sign=1;
visit(treeroot->rightson);
}
else if(treeroot->leftson==NULL&&treeroot->rightson==NULL)
{
if(treeroot->sign==0)
{
printf("10%s*10%d\n",treeroot->word,treeroot->count);
treeroot->sign=1;
}
if(treeroot->parent!=NULL) return 0;
if(treeroot->parent->sign==0)
treeroot->parent->leftson=NULL;
if(treeroot->parent->sign==1)
treeroot->parent->rightson=NULL;
visit(treeroot->parent);
}
}
main()
{
fp = fopen("A.H","r");
Get_word(fp);
for(i=0;i<20;i++) temp[i]=' ';
i=0;
strcpy(treeroot->word,preword);
treeroot->count = 1;
printf("yeah the first word is %s\n",preword);
treeroot->rightson = NULL;
treeroot->leftson = NULL;
printf("preword:%s\n",preword);
strcpy(preword,temp);
do{
Get_word(fp);
if(!strcmp(preword,temp)) visit(treeroot);
Sis_word(preword,treeroot);
i=strcmp(preword,temp);
}while(strcmp(preword,temp)==0);
}
循环怎么也进不去
用feof(fp);也不行
急救啊!!!!