Re: [gtk-list] GList and Combo



On Thu, May 14, 1998 at 10:54:18AM +0200, Marc Aubry wrote:
  GList* select_sizes (void)
  {
      guint i;
      gchar *size;
      GList *sizelist = NULL;
  
      size = (char *) calloc (2, sizeof(char));
      for (i=1; i<=5; i++)
      {
          sprintf (size, "%d", i);
-         sizelist = g_list_append (sizelist, size);
+         sizelist = g_list_append (sizelist, g_strdup(size));
      } /* end_for */
-     sizelist = g_list_append (sizelist, "end");
+     sizelist = g_list_append (sizelist, g_strdup("end"));
      return sizelist;
  } 

In your example you were building a GList with the same data in
every slot:-).
Remember to free the strings when you're done (and the glist) with
something like g_list_foreach(sizelist, g_free, NULL).

lupus



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