RE: Glib problem: trying to use gpointer pointing to a structure in a GList. Getting segfault
- From: "Albert Pala" <a Pala polkomtel com pl>
- To: <gtk-list gnome org>
- Subject: RE: Glib problem: trying to use gpointer pointing to a structure in a GList. Getting segfault
- Date: Fri, 8 Aug 2003 15:30:13 +0200
your record is pointer.
you have to allocate structure record and then use pointer to it.
struct {
guint index;
gchar *data;
} x, *record;
record = &x;
record->data = "blabla1"
albert pala
====== cut here ===============
#include <stdio.h>
#include <string.h>
#include <glib.h>
int main(int argc, char **argv)
{
GList *dlist = NULL, *list = NULL;
guint length,i;
struct {
guint index;
gchar *data;
} *record;
record->data = g_malloc(strlen("Lucas")+1);
g_strlcpy(record->data,"Lucas",strlen("Lucas")+1);
dlist = g_list_append(dlist, record);
record->data = g_malloc(strlen("Brasilino")+1);
g_strlcpy(record->data,"Brasilino", strlen("Brasilino")+1);
dlist = g_list_append(dlist, record);
length = g_list_length(dlist);
g_printf("%d \n",length);
record = NULL;
list = g_list_first(dlist);
while(list)
{
record = list->data;
g_print("%s\n",record->data);
list = list->next;
}
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]