Re: GtkList number of items? gtk_object_set_data (GList)?



>comboitem = g_malloc(sizeof(gchar)*20);
>strcpy(comboitem, "toto");
>liste = g_list_insert(liste, comboitem, (GCompareFunc) compare);
>strcpy(comboitem, "tata");
>liste = g_list_insert(liste, comboitem, (GCompareFunc) compare);
>/* ... */

this code is broken. you've just stored two instances of the same
pointer in the list; when the list is traversed, you will get:

	tata
	tata

not

	tata
	toto

don't forget to malloc more space before you pass the pointer to
G(S)List operations:

  comboitem = g_malloc(sizeof(gchar)*20);
  strcpy(comboitem, "toto");
  liste = g_list_insert(liste, comboitem, (GCompareFunc) compare);

  comboitem = g_malloc(sizeof(gchar)*20);
  strcpy(comboitem, "tata");
  liste = g_list_insert(liste, comboitem, (GCompareFunc) compare);

--p




[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]