H
hal22
Hello, I have a problem deleting lists. The function delete_all will
delete a complete list, starting with the entry given as parameter.
delete_one deletes one element of a list and returns the next. I want
to make these functions bullet proof, but it seems that I don't get
how to set the parameter to NULL after freeing the contents.
void delete_all( Monom* monom ){
while( monom != NULL ){
monom = delete_monom( monom );
}
}
static Monom*
delete_one( Monom* monom){
Monom *temp = monom->next;
free( monom );
monom = NULL;
return temp;
}
Lets say I have a list "test", the following gives an error:
delete_all( test );
delete_all( test );
This is fine:
delete_all( test );
test = NULL;
delete_all( test );
Thanks in advance.
Sorry for the double post, hit the wrong keys.
delete a complete list, starting with the entry given as parameter.
delete_one deletes one element of a list and returns the next. I want
to make these functions bullet proof, but it seems that I don't get
how to set the parameter to NULL after freeing the contents.
void delete_all( Monom* monom ){
while( monom != NULL ){
monom = delete_monom( monom );
}
}
static Monom*
delete_one( Monom* monom){
Monom *temp = monom->next;
free( monom );
monom = NULL;
return temp;
}
Lets say I have a list "test", the following gives an error:
delete_all( test );
delete_all( test );
This is fine:
delete_all( test );
test = NULL;
delete_all( test );
Thanks in advance.
Sorry for the double post, hit the wrong keys.