This pretty much accomplishes what you wanted, however, this could have memory leaks. Lets say your program works like this:
Code:
void Problem(struct node * b){
struct node *p = (struct node *) malloc (sizeof (struct node));
p = b;
returns p;
}
int main(void){
struct node *mem_leak = (struct node *)malloc(sizeof(struct node));
Problem(mem_leak);
return 0;
}
Okay, now if you are not very experienced the memory leak probably went under your radar but I'll explain. You allocated a block of memory to struct node *mem_leak via malloc. Immediately afterward you pointed it to a different block of data. The other block of data that it was pointing to in the first place didn't just disappear. So what you may want to do is free a struct before passing it in toe Problem.