Sign in to follow this  
Bruno

getting data from a pointer into a struct

Recommended Posts

Hi., Let's imagine i have this struct : struct BlaBla { char *xpto; int *xpta; char xx[100]; struct BlaBla *next; }; And i declare this two : BlaBla *Linked_list; BlaBla *Temp_Struct; Now, in my Linked_list, it's a ordinary linked list of for example 10 elements. I want to delete element 5 of that linked list, so i must connect position 4 to position 6. However i will need the contents of position 5 to use in some other location. So, i have the *Temp_Struct that will hold the info of position 5 Temp_Struct = Linked_list ( in position 5 ) The problem is obvious, when i delete Linked_list position 5, my Temp_Struct will also be deleted. So, i was thinking in using it without a pointer. So, my question is, is there a way to copy all the contents of the pointer to a new variable ? BlaBla Temp_Struct instead of BlaBla *Temp_Struct

Share this post


Link to post
Share on other sites
First you don't need to store the whole struct from number 5 becuase you are just deleting it anyways. The only thing you need to store from number 5 is the * to struct number six..


struct BlaBla Current_Link_List_Member;
struct BlaBla *Delete_Struct_Next;

Delete_Struct_Next = Current_Link_List_Member.Next; // While at loction five
Current_Link_List_Member.Next = Delete_Struct_Next; // While at loction four



This should be what you need.

theTroll

Share this post


Link to post
Share on other sites
yes,

BlaBla Temp_Struct = *pointer_to_position5_of_linked_list;


The contents of BlaBlha suggest that you're asking for trouble though. Who owns the memory pointed to by xpto and xtpa? does it get deleted when you delete a BlaBla? If so, then your Temp_Struct will contain pointers to invalid memory once you delete the 5th node in your list.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this