Answer the question
In order to leave comments, you need to log in
How to move data to an address?
Good afternoon! The question is: how to move data from one memory cell?
To make it clearer, I have a singly linked list like this:
typedef struct s_list
{
void* data;
struct s_list* next;
} t_list;
void delone(t_list** lst);
Answer the question
In order to leave comments, you need to log in
Hm. I'm not sure that I understood correctly, but moving any data from anywhere to anywhere and as much as you like (within the limits of available memory, of course) is done through memmove (). The thing is universal, but dangerous - the whole calculation of pointers, as well as the length of the movable section, is the programmer's concern, the call will simply crash the program via SIGSEGV if something is passed incorrectly.
I didn’t quite understand the question, but if you mean rewriting the pointer to the element to be deleted, then there are 2 approaches.
1) If the function is recursive, then let it return a new head of the list. If you don't want to delete the current element, then rewrite next with the result of calling next from this and return the current entry. If you need to delete, then clear the memory and return next.
2) If the function works in a loop, which is preferable, then you can just remember the previous element of the list. Move 2 pointers in parallel.
prev = cur;
cur = cur->next;
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question