Re: get integer/real number from gtk_entry_set_text
- From: Rudra Banerjee <bnrj rudra yahoo com>
- To: gtk-app-devel-list gnome org
- Subject: Re: get integer/real number from gtk_entry_set_text
- Date: Sat, 12 May 2012 21:13:19 -0400
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
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]