Code:struct node { char *string; struct node *left; struct node *right; }; struct node *leaf; main(){ leaf = (struct node *)malloc( sizeof( struct node ) ); FILE *in=fopen("c:\\str6.txt","r"); char str[40]; fscanf(in,"%s",str); leaf->string=str; fscanf(in,"%s",str); (leaf->left)=(struct node *)malloc( sizeof( struct node ) ); ((leaf->left)->string)=str; printf("\n\n"); printf("%s",(leaf->string)); printf("%s",((leaf->left)->string)); }
the first two strings in the file are "qwert" ,"asdfg"
but the output is showing as
asdfgasdfg
when i want
qwertasdfg
whats wrong with the code?,i am just learning tree's.



LinkBack URL
About LinkBacks


