Re: Cast from gchar* to int?



Ok, I am still not having any luck, here is some code examples for you all

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;


gchar *num = gtk_editable_get_chars(GTK_EDITABLE(contact_num_entry),0,-1);
gint i = 0;
i = atoi(num);
cout << i << endl;


So can someone please tell me why both the above return 0.

Basically what I am trying to do, is I have a entry field that will
accept numeric input. I then need to get that value, and increment it by
one.

So if I enter 4, I need to be able to increment it to 5. Pretty basic,
but I can't seem to get the value entered into a numeric data type to be
added or in another scenario subtracted.

I assume you can't subtract and add char* as if they were numeric data
types. I have not tried it, but I really doubt it could be done, so I am
pretty sure I will have to convert to a numeric data type to
add/subtract/etc.

Thanks.

-- 
Sincerely,
William L. Thomson Jr.
Support Group
Obsidian-Studios Inc.
439 Amber Way
Petaluma, Ca. 94952
Phone  707.766.9509
Fax    707.766.8989
http://www.obsidian-studios.com




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