I need to create a bynarytree of which information of a node is made of ISBN and price fields, data kept in a structure (book).
I write in a .txt file : ISBN=10 Price=100
ISBN=13 Price =1
how can i populate the bynarytree with this informations, from the file?
example:

void main()
{
bynarytree *rad;
book a;
FILE*f;
f=fopen("books.txt","r+");
while(!feof)
{
cin>>f>>a.ISBN>>a.price;
rad->info.ISBN=a.ISBN;
rad->info.price=a.price;
}
RSD(rad);
fclose(f);
}

my problem is what i write in while to make the link between what i wrote in file and the fields of the structure, because like this is not working.Thanks a lot

line 1: its int main() never ever void main()

line 7: feof is a function and it needs to be written as feof()

line 9: why are you using cin to read from a file? cin gets information from the keyboard (YOU type the characters) not from the file.

lines 10 and 11: That is just assigning those from some variables that are already in memory. It is not reading the data from the file at all. You might as well juse use a crystle ball to get the data for that binary tree.

Try calling fgets() to read the information from the file.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.