alireza_fn alireza_fn - 1 year ago 85
C Question

how to edit an existing data in glib lists

I use glib's lists (linked-lists) for storing a list of strings in my program. I'm already able to append, prepend or insert new items to the list but I can't edit an existing item in the list. I cannot find the appropriate function for editing items in glib's documentation. Is there any functions implemented in glib for doing this?

Answer Source

I think you're supposed to use the structure directly, as the internal structure is exposed:

struct GList {
  gpointer data;
  GList *next;
  GList *prev;

So, for example:

GList *bar = g_list_last(foo);
bar->data = NULL; //for instance
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download