LinuxQuestions.org
Visit Jeremy's Blog.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 06-14-2003, 02:23 PM   #1
OutToSea
LQ Newbie
 
Registered: Jun 2003
Posts: 14

Rep: Reputation: 0
Pointers && Gade PLZ HELP


Hi.

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.

Please help

Thanks.
 
Old 06-14-2003, 04:05 PM   #2
Hko
Senior Member
 
Registered: Aug 2002
Location: Groningen, The Netherlands
Distribution: Debian
Posts: 2,536

Rep: Reputation: 111Reputation: 111
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)

Last edited by Hko; 06-14-2003 at 04:22 PM.
 
Old 06-14-2003, 04:10 PM   #3
acid_kewpie
Moderator
 
Registered: Jun 2001
Location: UK
Distribution: Gentoo, RHEL, Fedora, Centos
Posts: 43,417

Rep: Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985
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
 
Old 06-14-2003, 07:00 PM   #4
OutToSea
LQ Newbie
 
Registered: Jun 2003
Posts: 14

Original Poster
Rep: Reputation: 0
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.

tnx for your help.
 
Old 06-15-2003, 04:15 AM   #5
acid_kewpie
Moderator
 
Registered: Jun 2001
Location: UK
Distribution: Gentoo, RHEL, Fedora, Centos
Posts: 43,417

Rep: Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985
if you're getting these invalid pointer things then you're definitely using gtk incorrectly.

gtk_entry_set_text(widget, string);

will set it in c, no idea what you're doing at the moment, but trying to use the widget data pointer as data itself is an amzaingly bad idea.
 
Old 06-15-2003, 06:21 AM   #6
Hko
Senior Member
 
Registered: Aug 2002
Location: Groningen, The Netherlands
Distribution: Debian
Posts: 2,536

Rep: Reputation: 111Reputation: 111
Quote:
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) 
      */

Last edited by Hko; 06-15-2003 at 06:25 AM.
 
Old 06-15-2003, 08:27 AM   #7
OutToSea
LQ Newbie
 
Registered: Jun 2003
Posts: 14

Original Poster
Rep: Reputation: 0
Right. Didn't catch the sprinf part before. (again, out here at sea sometimes the sats don't tramsmit all my data heh...)

So anyhow the sprintf statement worked.

And acid, Iwasn't using the pointer as the data itself. But tnx.

Preciate the help guys. I got it running now.

Take it eazy.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
zsnes && logitech dual action gamepad && dpad woes John5788 Linux - Games 5 10-29-2008 09:56 PM
C programming pointers & recursive exvor Programming 8 08-16-2005 09:24 AM
Japanese canna won't work : Warning: &#12363;&#12394;&#28450;&#23383;&#22793;&am OrganicOrange84 Debian 3 06-30-2005 02:28 PM
Ph&#7909;c h&#7891;i d&#7919; li&#7879;u b&#7883; m&#7845;t???, c&#7913; pollsite General 1 06-27-2005 12:39 PM
Javascript && Bookmark -- need help plz DaFrEQ Programming 7 10-09-2003 01:13 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 11:37 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration