GTK+ Forums

Discussion forum for GTK+ and Programming. Ask questions, troubleshoot problems, view and post example code, or express your opinions.
It is currently Thu Oct 02, 2014 6:24 am

All times are UTC




Post new topic Reply to topic  [ 6 posts ] 
Author Message
 Post subject: converting character to gchar problem
PostPosted: Sun Jun 25, 2006 3:28 am 
Offline

Joined: Sun Jun 25, 2006 3:19 am
Posts: 2
my problem is:
Code:
   gchar *uri = "/home/chris/pictures/test.jpg";
   gchar *result="";
   for(gint i=gcharLen(uri)-1;i>=0;i--){
      if(uri[i]=='/')break;
      g_print("#%d %c\n",i,uri[i]);
      result+=uri[i];
   }
   g_print(result);


what this function is going to return is the name of the file test.jpg
the logic is a little wrong. if it did work it would be backwards.
anyways...
it prints out a bunch of unicode garbage at me.

how can i append characters to result as gchar or string?


Top
 Profile  
 
 Post subject:
PostPosted: Sun Jul 02, 2006 10:17 pm 
Offline
Never Seen the Sunlight

Joined: Wed Sep 21, 2005 12:07 am
Posts: 563
Location: Portland, OR USA
The 2 things I would say are first, to allocate memory for the result string (such as using g_new() or g_new0()).

Secondly, the result+=uri[i] seems funny to me. Are you appending a character? You might want to have another variable counting from 0 up and do something like result[j] = uri[i];

If you're trying to get just the filename of a path, try using g_path_get_basename:
Code:
gchar *uri = "/home/chris/pictures/test.jpg";
gchar *result = g_path_get_basename(uri);

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


Top
 Profile  
 
 Post subject:
PostPosted: Sun Aug 27, 2006 11:25 pm 
Offline

Joined: Sun Jun 25, 2006 3:19 am
Posts: 2
it works.
thank you very much.

i was very suprised to see someone respond to my question.. it doent seem like anyone realy uses this forum. in fact i stop check back here month ago. and one day, after going through old bookmarks, i said 'hey lets see if anyone replyed to my question', and here i am.

so thank you very much.


Note: gchars end in zero. dont forget to put that when your trying something like this.
Code:
gchar* word[3];
word[0] = 'H'
word[1] = 'I'
word[2] = 0


Top
 Profile  
 
 Post subject:
PostPosted: Mon Aug 28, 2006 1:03 am 
Offline
Never Seen the Sunlight

Joined: Wed Sep 21, 2005 12:07 am
Posts: 563
Location: Portland, OR USA
np.

Yeah, these forums aren't exactly "catching on" but... who knows. Ain't costing me much to have them up and I'm always here to try and answer a question.

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


Top
 Profile  
 
 Post subject:
PostPosted: Wed Aug 30, 2006 1:17 am 
Offline
Never Seen the Sunlight

Joined: Wed Sep 21, 2005 3:07 am
Posts: 384
Location: Fairfax, Virginia
I'm just waiting for them to catch on! I've consistently checked them a few times a week since you announced it on the GTK+ list. I still do the same thing with gnomedev.com as well. I just have problems giving up on things, LOL.

_________________
Andrew Krause

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


Top
 Profile  
 
 Post subject:
PostPosted: Wed Aug 30, 2006 3:28 am 
Offline
Never Seen the Sunlight

Joined: Wed Sep 21, 2005 12:07 am
Posts: 563
Location: Portland, OR USA
Same here :)

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


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

All times are UTC


Who is online

Users browsing this forum: No registered users and 2 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