ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
I'm currently in the middle of the Gulf of Mexico on a job.
I have very limited access to inet not to mention it takes forever and a day to dl a google page. (with no search.. damn stats...)
Anyway, I'm having trouble with pointers in glade.
Actually, problem is this:
Have program where user inputs a # into a text entry field. (entry1)
I want to grab the inputed # and do whatever with it.
However, I keep getting incompatible pointer blah blah types n such.
There isn't much doqs for glade so I'm curious as to how to pull an int from a text intry widget. I can put a damn char string all day and strncpy() it to whatever and munipulate it, but not numbers.
You may want to have a look at the man pages of the atoi(), atof(), strtol() and strtod() functions. These are standard C functions (#include <stdlib.h>) for converting numbers-in-strings to numbers (int,long,double...).
However I'm not familiar with programming in GTK, glib nor did I ever try glade, so there may be a nicer solution offered by those libs that I may not be aware of...
BTW, you can use sprintf to do the opposite (i.e. printf-ing a number to a string)
if you're using strncpy() to get text values from a gtk entry, i'd suggest you're using it incorrectly
gtkentry->get_text()
will get the content of the widget, whatever the content. the fact that it is a number is totally irrelevant. This is not going to be a glade issue,. but a gtk one, i'd suggest spending a bit of time reading some of the examples for gtk at gtk.org
Thanks Hko. That worked for me. Just had to convert the str to an int once it was grabbed. Now I can munipulate it all I want. heh.. however (ofcourse there is a however)
Now that I've got my str from entry1 converted to an int say I do a simple int++ and want to return the new value to entry2.
How would I go about putting the new int into the new entry2?
I thought i'd be able to simply throw it up like a normal string (eventho its an int) however its telling me I have invalid pointer type cast.
Do I have to convert it back to a str? if so how? I can't seem to find anything on converting int to str.
Originally posted by OutToSea How would I go about putting the new int into the new entry2?
[..snip..]
Do I have to convert it back to a str? if so how? I can't seem to find anything on converting int to str.
Like I said in the footnote of my previous post:
Quote:
BTW, you can use sprintf to do the opposite (i.e. printf-ing a number to a string)
You then can use the same format specifiers as with printf() to specify how you want the integer (or whatever) printed into the new string, e.g. hexadecimal, octal, with what precision (for double's or real's)...
So basically something like:
Code:
char str1[10];
char str2[10];
int n;
/* First get the string into 'str1' using:
* gtkentry->get_text();
* (see acid_kewpie's first post) */
*/
n = atoi(str1);
n++;
sprintf(str2, "%d", n); /* print int into string 'str2' */
/* Finally put the string 'str2' into the widget with
* gtk_entry_set_text(widget, str2);
* (see acid_kewpie's second post)
*/
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.