I tried putting #include <stdlib.h> and i=atoi(entry); printf("%d", i );
Now the complete program looks like: #include <stdlib.h> #include <stdio.h> #include <gtk/gtk.h> void enter_callback( GtkWidget *widget, GtkWidget *entry ) { gchar *entry_text; entry_text = gtk_entry_get_text(GTK_ENTRY(entry)); printf("Entry contents: %s\n", entry_text); } int main( int argc, char *argv[] ) { GtkWidget *window; GtkWidget *vbox, *hbox; GtkWidget *entry; GtkWidget *button; GtkWidget *check; GtkWidget *table; gtk_init (&argc, &argv); int i; double d; /* create a new window */ window = gtk_window_new(GTK_WINDOW_TOPLEVEL); gtk_window_set_title(GTK_WINDOW (window), "GTK Entry"); gtk_signal_connect(GTK_OBJECT (window), "delete_event", (GtkSignalFunc) gtk_exit, NULL); /* CREATE TABLE */ table = gtk_table_new (5, 3, TRUE); gtk_container_add (GTK_CONTAINER (window), table); /* *CREATE ENTRY FOR ATOM 1 */ entry = gtk_entry_new_with_max_length (2); gtk_table_attach_defaults (GTK_TABLE (table), entry, 0, 1, 0, 1); gtk_signal_connect(GTK_OBJECT(entry), "activate", GTK_SIGNAL_FUNC(enter_callback), entry); gtk_entry_set_text (GTK_ENTRY (entry), "A"); gtk_widget_show (entry); i=atoi(entry); printf("%d", i ); gtk_widget_show (button); gtk_widget_show (table); gtk_widget_show(window); gtk_main(); return(0); } but it still fails with segmentation fault. $gcc -g mini_ten.c -o ften `pkg-config --cflags gtk+-2.0` `pkg-config --libs gtk+-2.0` mini_ten.c: In function ‘enter_callback’: mini_ten.c:11:14: warning: assignment discards ‘const’ qualifier from pointer target type [enabled by default] mini_ten.c: In function ‘main’: mini_ten.c:51:1: warning: passing argument 1 of ‘atoi’ from incompatible pointer type [enabled by default] /usr/include/stdlib.h:148:12: note: expected ‘const char *’ but argument is of type ‘struct GtkWidget *’ $./ften Segmentation fault (core dumped) On Sat, 2012-05-12 at 21:01 -0400, Rudra Banerjee wrote: > Friends, > How can I convert gtk_entry_set_text to an integer/real number? > Below is a minimal example. Please suggest. > #include <stdio.h> > #include <gtk/gtk.h> > > void enter_callback( GtkWidget *widget, > GtkWidget *entry ) > { > gchar *entry_text; > entry_text = gtk_entry_get_text(GTK_ENTRY(entry)); > printf("Entry contents: %s\n", entry_text); > } > > int main( int argc, > char *argv[] ) > { > > GtkWidget *window; > GtkWidget *vbox, *hbox; > GtkWidget *entry; > GtkWidget *button; > GtkWidget *check; > GtkWidget *table; > > gtk_init (&argc, &argv); > > /* create a new window */ > window = gtk_window_new(GTK_WINDOW_TOPLEVEL); > gtk_window_set_title(GTK_WINDOW (window), "GTK Entry"); > gtk_signal_connect(GTK_OBJECT (window), "delete_event", > (GtkSignalFunc) gtk_exit, NULL); > > /* CREATE TABLE > */ > > table = gtk_table_new (5, 3, TRUE); > gtk_container_add (GTK_CONTAINER (window), table); > > /* > *CREATE ENTRY FOR ATOM 1 > */ > entry = gtk_entry_new_with_max_length (2); > gtk_table_attach_defaults (GTK_TABLE (table), entry, 0, 1, 0, 1); > gtk_signal_connect(GTK_OBJECT(entry), "activate", > GTK_SIGNAL_FUNC(enter_callback), > entry); > gtk_entry_set_text (GTK_ENTRY (entry), "A"); > gtk_widget_show (entry); > > gtk_widget_show (button); > gtk_widget_show (table); > gtk_widget_show(window); > > gtk_main(); > return(0); > } > > _______________________________________________ > gtk-app-devel-list mailing list > gtk-app-devel-list@gnome.org > http://mail.gnome.org/mailman/listinfo/gtk-app-devel-list _______________________________________________ gtk-app-devel-list mailing list gtk-app-devel-list@gnome.org http://mail.gnome.org/mailman/listinfo/gtk-app-devel-list