heres my little problem, i need to save some information to a file that is stored in a binary tree, getting the information is not a problem, <gotta love recursion aint you>, now to the problem, the code for opening the file is within the function and obviously it keeps opening the file with every item from the binary tree, so whats the problem i hear you ask, well i've already got stuff in the file that i've loading into the program and when i save that stuff and some new stuff i want to be able to erase the contents and start from fresh, but with every pass with recursion the new info gets erased also, i cant put the file open routine outside of the function cause the function will still call it every time
heres the code
void saveContents(PTRnode* &root, char pathname[60])
{
FILE *fp; //file pointer
int temp;
if(root==NULL)
{
return;
}
else
{
fp = fopen(pathname, "w");
fprintf(fp,"%s\n%s\n%d\n",root->data.artist, root->data.title, root->data.numberTracks);
for(temp=1;temp<=root->data.numberTracks;temp++)
{
fprintf(fp,"%s\n",&root->data.SongList[temp]);
}
fclose(fp);
saveContents(root->left, pathname);
saveContents(root->right, pathname);
}
}
i hope that made sense all that typing, hope someone can help me
thanx in advance korbitz