Jump to content
  • Advertisement
Sign in to follow this  
Bruno

getting data from a pointer into a struct

This topic is 4274 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

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
Advertisement
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
I'm deleting it but i need a copy of it.
That number 5 is going to be transfered to another list

Share this post


Link to post
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 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
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!