GTK+ Forums

Discussion forum for GTK+ and Programming. Ask questions, troubleshoot problems, view and post example code, or express your opinions.
It is currently Sat Dec 20, 2014 9:35 pm

All times are UTC




Post new topic Reply to topic  [ 7 posts ] 
Author Message
 Post subject: Converting int to const gchar*
PostPosted: Sat May 26, 2007 1:40 am 
Offline
Familiar Face

Joined: Fri May 25, 2007 8:36 am
Posts: 13
Location: Iran
I want to print an int value.
How we can convert int value to const gchar *?
Int a=2
G_print(a)
Above codes give error.


Top
 Profile  
 
 Post subject:
PostPosted: Sat May 26, 2007 7:49 am 
Offline
Never Seen the Sunlight

Joined: Wed Sep 21, 2005 12:07 am
Posts: 563
Location: Portland, OR USA
In what language?

_________________
Micah Carrick - Forum Administrator
http://www.micahcarrick.com


Top
 Profile  
 
 Post subject:
PostPosted: Sat May 26, 2007 8:06 am 
Offline
Familiar Face

Joined: Fri May 25, 2007 8:36 am
Posts: 13
Location: Iran
c++


Top
 Profile  
 
 Post subject:
PostPosted: Sat May 26, 2007 3:01 pm 
Offline
Never Seen the Sunlight

Joined: Wed Sep 21, 2005 3:07 am
Posts: 384
Location: Fairfax, Virginia
Why not just use:

Code:
g_printf ("%d", a);


Thast replaces %d with the integer value "a".

_________________
Andrew Krause

Foundations of GTK+ Development: Buy now for only $31.49!


Top
 Profile  
 
 Post subject:
PostPosted: Sat May 26, 2007 5:23 pm 
Offline
Never Seen the Sunlight

Joined: Wed Sep 21, 2005 12:07 am
Posts: 563
Location: Portland, OR USA
And if for some reason you really need to convert an integer into a gchar* then you could use g_ascii_dtostr()

_________________
Micah Carrick - Forum Administrator
http://www.micahcarrick.com


Top
 Profile  
 
 Post subject:
PostPosted: Sat May 26, 2007 5:32 pm 
Offline
Never Seen the Sunlight

Joined: Wed Sep 21, 2005 12:07 am
Posts: 563
Location: Portland, OR USA
And since we're on the subject, if you need to construct a sentence for say, displaying in a dialog or something, which needs the value of an integer variable in it, then you can use the g_strdup_printf() or something similar. Check out the String Utility Functions in the GLib manual.

Cheers.

_________________
Micah Carrick - Forum Administrator
http://www.micahcarrick.com


Top
 Profile  
 
 Post subject:
PostPosted: Sun May 27, 2007 6:21 am 
Offline
Familiar Face

Joined: Fri May 25, 2007 8:36 am
Posts: 13
Location: Iran
thanks for your help


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 7 posts ] 

All times are UTC


Who is online

Users browsing this forum: No registered users and 3 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group