Originally Posted by
Click_here
We are going to need to see more of your code.
The function adjust is
Code:
typedef struct node{
char data[100];
node *left,*right;
char* n;
}Node, *NodePtr;
void adjust(NodePtr root, FILE * in2)
{
char str[100];
char * result;
NodePtr tnp=NULL, tmp=NULL, first=NULL;
fgets(str,100,in2);
int i=0;
result=strtok(str," ");
if(result!=NULL && *result!='\n' && result!='\0' && result!="\n")
{
tnp=find2 (root,result);
first=tnp;
}
while (result!=NULL && *result!='\n' && result!='\0' && result!="\n")
{
i++;
result = strtok(NULL," ");
if (result!=NULL && *result!='\n' && result!='\0' && result!="\n")
{
tmp=find2(root,result);
tnp->n=tmp->data;
}
else
tmp->n=first->data;
if (result!=NULL && *result!='\n' && result!='\0' && result!="\n")
tnp=find2 (root,result);
}
}
My Main is
Code:
char main ()
{
NodePtr root=NULL, tnp;
char test[20]="yo",word[20];
char *result=NULL, *c=0;
char str[16];
int op=0;
FILE * in=fopen("C:\\Test\\input.txt","r");
FILE* out=fopen("C:\\Test\\input.txt","a");
while (!feof(in))
{
fscanf(in,"%s",str);
NodePtr tnp=find(root,str);
if (root==NULL) root=tnp;
}
rewind(in);
fseek(in, 0, SEEK_SET);
while (!feof(in))
adjust(root, in);
display(root,word);
fclose(out);
fclose(in);
getch();
}
Display function would find a word in the Binary Tree, then prints out all the 'n' values in structure.