Re: GList



On Wed, 2003-07-30 at 00:02, umesh wrote:
Using following code combo box should fill with values 0,1,2,3 rather
it is filling with values is 3,3,3,3(last number)
What could be the problem? please help me in this regard.
 
combo = lookup_widget(GTK_WIDGET(button), "combo1");
GList  *list=NULL;
char s[0];
int j;
 
for (j=0;j<=3;j++)
  {
    sprintf(s,"%d",j);
    list=g_list_append(list,(void *)s);
  }
 
  gtk_combo_set_popdown_strings (GTK_COMBO (combo),list);
  g_list_free(list);

First, please don't send HTML email to mailing lists.  Particularly the
crappy non-accessible HTML generated by Outlook.

The problem is that you're appending a pointer to the GList, then
writing to that memory location, then adding that same pointer again,
etc.  s is a pointer to a char.  It's a memory address.  The line

sprintf (s, "%d", j);

writes the stringified version of j into the memory pointed to by s. 
This doesn't at all change where s is pointing, only what's there. 
Basically, you're adding the same thing four times.

--
Shaun





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