Re: Cast from gchar* to int?
- From: Allin Cottrell <cottrell wfu edu>
- To: "William L. Thomson Jr." <support obsidian-studios com>
- Cc: gtk-app-devel-list <gtk-app-devel-list gnome org>
- Subject: Re: Cast from gchar* to int?
- Date: Tue, 24 Sep 2002 20:10:37 -0400 (EDT)
On 24 Sep 2002, William L. Thomson Jr. wrote:
Neither of these work, and both return the exact same result, 0.
Now the 0 is not the one that I initialized gint i to, but the value that
is returned from passing the const gchar *num to the atoi function.
So if I start with gint i = 4, it will still output 0;
const gchar *num = gtk_entry_get_text(GTK_ENTRY(contact_num_entry));
gint i = 0;
i = atoi(num);
cout << i << endl;
If the string returned by gtk_entry_get_text() is valid numeric input
I can't see any reason why atoi shouldn't convert it to an int. A
couple of suggestions: (i) Can you really mix C++ and C in this way?
("cout" along with the gtk calls). (ii) Arrange to have your program
print the string returned by gtk_entry_get_text() printed to stderr
before the conversion -- then perhaps you'll see why the conversion is
failing.
const gchar *num = gtk_entry_get_text(GTK_ENTRY(contact_num_entry));
gint i = 0;
fprintf(stderr, "Got supposedly numeric string '%s'\n", num);
i = atoi(num);
fprintf(stderr, "Int conversion of num = %d\n", i);
Allin Cottrell.
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]