0
How do I print the data of a GSList in C? and how can iterate through the list and copy the data?
I need to iterate through the elements contained in a GSList in C and copy them, and save them using gtk_file_chooser_get_uris()
1 Réponse
0
This is the definition of GSList in the GTK documentation.
struct GSList {
gpointer data;
gpointer next;
}
You have a pointer for the data, and a pointer for the next GSList element. You just need to use the data, and then update the pointer to point to the next GSList element, check if next is NULL, if it is not NULL, use the data again, if it is, exit and free the list.
---
void print_uris(GtkFileChooser* chooser)
{
GSList* uris = gtk_file_chooser_get_uris(chooser);
GSList* node;
for (node = uris; node != NULL; node = node->next) {
printf("URI: %s\n", (gchar*) node->data);
}
g_slist_free_full(uris, g_free);
}



