Your function doesn't handle the case when the left and/or right child is not null.
Your search_node function doesn't return anything on line 26 and 27.
You also need to change one of the child pointers (left or right) of the parent node because you don't want any pointers to point to the node after you have freed it.
first, I want to handle only this case , then I'll take care of others.
search_node will always run through the binary tree till it finds a null node and then it goes all the way back.( i could write return but nothing would change)
I'll repeat what Peter87 said: search_node() doesn't return anything on lines 26 and 27. It calls itself recursively but it then ignores the returned value.
In your delete function, line 49 sets the local variable root to NULL, but whatever pointer (tree->root or some node's left or right pointer) pointed to the node is still set, creating a dangling pointer.
it worked perfectly if I didn't write any return on line 26 and 27.
It worked by accident. For example, the return value may have been stored in a CPU register so the right value happened to be there.
The thing you have to realize with recursive functions is that each call has different parameters, different local variables and a different return value.
so the solution to my problem would be to somehow create a double pointer function and take care of it ?
You could have search_node return a reference to the pointer:
This is still wrong , because I don't want to pass directly the tree's root node as parameter in the main function,.
I don't want to mess my main with this ex: delete(&tree,'a')