Re: GList



Hi umesh,

Le mer 30/07/2003 Ã 10:05, umesh a Ãcrit :
for (j=0;j<=3;j++)
  {
    sprintf(s,"%d",j);
    list=g_list_append(list,(void *)s);

Here, you append to the list a pointer to the array s. Even though the
value which this pointer points to changes when you iterate through your
for loop, the value is 3 at the end of the loop. This means your list
contains three pointers pointing to the same data at the end of the for
loop...

Obviously, you need to create three different strings and append them to
the list. I'd try using:

list = g_list_append (list, g_strdup_printf ("%d", j));

If you do this, don't forget to free each item in the list before
g_list_freeing it.

regards,
Mathieu
-- 
Mathieu Lacage <mathieu gnu org>





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