LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
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 12-20-2007, 12:00 PM   #1
Carunkumar
Member
 
Registered: Sep 2006
Location: chennai
Distribution: fedora core 8
Posts: 106

Rep: Reputation: 15
how to use a gchar ** variable in gtk+


I have a function that returns an argument of type gchar**. I need to get the strings.

I thought the strings would be terminated by a NULL and used a simple code to display the strings..

Code:
gchar **o;

..
..

gint i = 0;
while(o[i] != NULL)
{
       g_print("%s",output[i]);
       i++;
}
I get segmentation fault after the last string gets displayed.. how should I deal with it??
 
Old 12-20-2007, 03:33 PM   #2
kotnik
Member
 
Registered: Nov 2004
Location: Novi Sad, Serbia
Distribution: Debian, Slackware, Gentoo, openSuSE
Posts: 254

Rep: Reputation: 31
Strings are \0-terminated.
 
Old 12-26-2007, 04:08 PM   #3
MicahCarrick
Member
 
Registered: Jul 2004
Distribution: Fedora
Posts: 241

Rep: Reputation: 31
Are you referring to a function like g_strsplit() in which the array of strings is terminated with NULL? If so, then your only problem is that you're using o and output... two different variables.

Try this:

Code:
#include <gtk/gtk.h>

int main()
{

    gchar** o = g_strsplit ("apple:orange:bananna",":",-1);
    gint i=0;
    
    while(o[i] != NULL)
    {
           g_print("%s\n",o[i]);
           i++;
    }
    
    return 0;
}
If you compile that and run it, you should get three lines printed, "apple", "orange", and "bananna".
 
Old 02-15-2008, 08:57 AM   #4
Carunkumar
Member
 
Registered: Sep 2006
Location: chennai
Distribution: fedora core 8
Posts: 106

Original Poster
Rep: Reputation: 15
Thank you.. I used the same variable name only. By mistake I posted o and output. Reason for getting a segmentation fault is I was trying to use it on the value returned by g_spawn_command_line_snyc() which was not an array of null terminated strings. Seeing the type of the contents of child's stdout, I thought it to be an array of null terminated strings.
 
  


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
Replace variable with user defined variable ce124 Programming 10 04-13-2007 09:29 AM
string to gchar* BackwardsDown Programming 7 09-28-2006 07:17 PM
setting a variable variable in a script... this works, but could it be more elegant? pwc101 Programming 3 08-18-2006 11:23 AM
GTK + 2.4 ... Enviroment Variable Settings? miskiw Linux - Software 2 04-25-2004 09:48 AM
Gimp Tool Kit gchar Widget comparison... chewysplace Programming 2 01-30-2004 04:30 PM

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

All times are GMT -5. The time now is 06:44 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