RE: newbie question, convert gchar to int?
- From: martyn 2 russell bt com
- To: infamous_godhand yahoo com, gtk-app-devel-list gnome org
- Subject: RE: newbie question, convert gchar to int?
- Date: Thu, 18 Sep 2003 12:13:38 +0100
Hello, I am trying to convert a string which the user
entered in the text entry box into a type int, I tried
to use atoi but when I print it out, it didn't give me
the integer instead it gave me the address of that
string. Any suggestions? thanks in advance.
All you should have to do is:
G_CONST_RETURN gchar *text = NULL;
text = gtk_entry_get_text(GTK_ENTRY(myentry));
if(text && g_utf8_strlen(text,-1) > 0)
{
gint number = -1;
number = atoi(text);
g_message("the number is :%d", number);
}
If you are interested in catching errors based on users entering non numeric
characters, perhaps you should consider either:
number = g_ascii_strtod(text, &endptr);
or using a GtkSpinButton where only numeric values are excepted:
http://developer.gnome.org/doc/API/2.0/gtk/GtkSpinButton.html
Regards,
Martyn
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]