GTK+ Forums Forum Index GTK+ Forums
Discussion forum for GTK+ and Programming. Ask questions, troubleshoot problems, view and post example code, or express your opinions.
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

converting character to gchar problem

 
Post new topic   Reply to topic    GTK+ Forums Forum Index -> GTK+ Programming
Author Message
paxmanchris



Joined: 25 Jun 2006
Posts: 2

PostPosted: Sun Jun 25, 2006 3:28 am    Post subject: converting character to gchar problem Reply with quote

my problem is:
Code: (Plaintext)
1
2
3
4
5
6
7
8
9
10

    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?
Back to top
Micah Carrick
Never Seen the Sunlight


Joined: 21 Sep 2005
Posts: 480
Location: Portland, OR USA

PostPosted: Sun Jul 02, 2006 10:17 pm    Post subject: Reply with quote

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: (Plaintext)
1
2
3
4

gchar *uri = "/home/chris/pictures/test.jpg";
gchar *result = g_path_get_basename(uri);
Back to top
paxmanchris



Joined: 25 Jun 2006
Posts: 2

PostPosted: Sun Aug 27, 2006 11:25 pm    Post subject: Reply with quote

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: (Plaintext)
1
2
3
4
5
6

gchar* word[3];
word[0] = 'H'
word[1] = 'I'
word[2] = 0
Back to top
Micah Carrick
Never Seen the Sunlight


Joined: 21 Sep 2005
Posts: 480
Location: Portland, OR USA

PostPosted: Mon Aug 28, 2006 1:03 am    Post subject: Reply with quote

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.
Back to top
openldev
Never Seen the Sunlight


Joined: 21 Sep 2005
Posts: 386
Location: Fairfax, Virginia

PostPosted: Wed Aug 30, 2006 1:17 am    Post subject: Reply with quote

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.
Back to top
Micah Carrick
Never Seen the Sunlight


Joined: 21 Sep 2005
Posts: 480
Location: Portland, OR USA

PostPosted: Wed Aug 30, 2006 3:28 am    Post subject: Reply with quote

Same here :)
Back to top
Display posts from previous:   
Post new topic   Reply to topic    GTK+ Forums Forum Index -> GTK+ Programming All times are GMT
Page 1 of 1

 


Powered by phpBB © 2001, 2005 phpBB Group
CodeBB 1.0 Beta 2
Protected by Anti-Spam ACP