0

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

Edited by Nick Evan: Please put your code BETWEEN the opening and closing tag

2
Contributors
1
Reply
2
Views
7 Years
Discussion Span
Last Post by Ancient Dragon
0

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.

Edited by Ancient Dragon: n/a

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.