Re: int -> char (label)...



On Fri, Jul 26, 2002 at 03:50:51PM +0100, sefo wrote:
hey,

i got a function that does a calculation and displays the result in a label.
The prblm is that i can't pass an int to gtk_label_new();

void calculate(GtkWidget *widget, GtkWidget **Entries) {
  GtkWidget *dialog, *label, *okay_button;
  gint res;
  gchar *txt1, *txt2, *txt3, *txt4, *b00;
  txt1=gtk_entry_get_text(GTK_ENTRY(Entries[0]));
  txt2=gtk_entry_get_text(GTK_ENTRY(Entries[1]));
  txt3=gtk_entry_get_text(GTK_ENTRY(Entries[2]));
  txt4=gtk_entry_get_text(GTK_ENTRY(Entries[3]));
/*values from the entries are converted into int + calculation*/
  res=atoi(txt1)+atoi(txt2)+atoi(txt3)+atoi(txt4);

  g_print("result: %d\n", res);/*here it works*/

/*trying to convert int to char to put it in the label*/
  snprintf(b00, sizeof(b00), "%d", res);

/*DIALOG*/
  dialog = gtk_dialog_new();
  gtk_window_set_title(GTK_WINDOW(dialog), "Dialog");
  gtk_widget_set_usize(dialog, 200, 100);
  label = gtk_label_new (b00);
....etc.

any idea?
_______________________________________________
gtk-app-devel-list mailing list
gtk-app-devel-list gnome org
http://mail.gnome.org/mailman/listinfo/gtk-app-devel-list

Looks to me like your real problem is youre using snprintf on b00 which
has no memory allocated for it.  Bad mojo.  Might I suggest the
following:

/* Start */
gchar *b00;

b00 = g_strdup_printf("%d", res);
label = gtk_label_new(b00);
...
g_free(b00);
/* End */

-Scott
-- 
We are not humanity.
-B



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