# 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 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 fiveCurrent_Link_List_Member.Next = Delete_Struct_Next;  // While at loction four

This should be what you need.

theTroll

##### Share on other sites
I'm deleting it but i need a copy of it.
That number 5 is going to be transfered to another list

##### Share on other sites
I'm deleting it but i need a copy of it.
That number 5 is going to be transfered to another list

##### 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.

## Create an account

Register a new account

• ### Forum Statistics

• Total Topics
627719
• Total Posts
2978796

• 10
• 9
• 21
• 14
• 12