Re: numerical buttons labels cont'd URGENT



Pierre CHATEL wrote:
> > > void
> > > on_button_click_event2 (GtkWidget *button, gpointer user_data)
> > > {
> > >   char *str;
> > >   int i;
> > >   gtk_label_get(GTK_LABEL(GTK_BIN(button)->child), &str);
> > >   i = atoi(str);
> > >   i--;
> > >   sprintf(str,"%i",i);
ARGH! You're writing in UNALLOCATED memory. *EVERYTHING* could happen,
including fdisk /dev/hda :-)
Change the previous char *str to char str[16] ...
> > >   g_print("%s",str); /* The new value is displayed for debugging */
> > >   gtk_label_set(GTK_LABEL(GTK_BIN(button)->child), str);
> > > }
> Nop, i'm using gtk1.2, and it's not working !
New to C programming? :-)
> can someone help me ?
memcheck could help you tack those errors...
> the str variable in the on_button_click_event2 callback can't be const
> because i need to do gtk_label_get and sprintf to it...how can i
> 'convert' a it to a const char* befor sending it to gtk_label_set  ????
No need to convert. From non-const to const it's automatic (there, const
just says the function does NOT write in the string you pass to it).

BYtE,
 Diego.



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