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 12-20-2008, 10:05 PM   #1
aarontwc
Member
 
Registered: Oct 2008
Posts: 66

Rep: Reputation: 15
Parsing Options using g_option_context_parse in GTK


Hi there,

I am trying to obtain values for my variables through the command line. But the values I get for my variables are returning rubbish. Any idea what I am missing here?

Variables:
Code:
static gchar port[1024];
static gchar localhostname[1024] = "";
static gchar challenge[1024] = "";
static gint verbose = 0;
Entries:
Code:
static GOptionEntry entries[] =
{
  { "host", 'h', 0, G_OPTION_ARG_STRING, &localhostname, "Specify the host to connect to", "HOST" },
  { "port", 'p', 0, G_OPTION_ARG_STRING, &port, "Specify the port to connect to", "PORT" },
  { "challenge", 'c', 0, G_OPTION_ARG_STRING, &challenge, "Specify the challenge when connecting", "CHALLENGE"},
  { "test", 't', 0, G_OPTION_ARG_INT, &test, "Specify the challenge when connecting", "TEST"},
  { "verbose", 'v', 0, G_OPTION_ARG_NONE, &verbose, "Be verbose", NULL },
};
Main:
Code:
    GError *error = NULL;
    GOptionContext *context;
    context = g_option_context_new ("Launch ISR Thin Viewer");
    g_option_context_add_main_entries (context, entries, NULL);
    g_option_context_add_group (context, gtk_get_option_group (TRUE));
    if (!g_option_context_parse (context, &argc, &argv, &error)) {
        g_print ("Option parsing failed: %s\n", error->message);
        exit (1);
    }

    printf ("My port is: %s\n", &port);
Any ideas? The above function returns me: My port is: ��
 
Old 12-20-2008, 10:54 PM   #2
aarontwc
Member
 
Registered: Oct 2008
Posts: 66

Original Poster
Rep: Reputation: 15
Found the answer!

Code:
static gchar *port = "";
static gchar *localhostname = "";
static gchar *challenge = "";
 
  


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
LXer: Options Parsing and Keywords LXer Syndicated Linux News 0 10-18-2007 04:40 AM
gtk appl to run in firefox on other host -- options? glaubstas Linux - Software 3 07-22-2007 08:11 AM
LXer: Parsing Options in Shell, Perl and C LXer Syndicated Linux News 0 04-16-2007 01:01 AM
parsing files using gtk shandy^^^ Programming 0 01-26-2006 10:02 AM
Kernel 2.6.2 options question - LOCKED options ? tvojvodi Linux - General 0 02-17-2004 04:23 AM

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

All times are GMT -5. The time now is 12:36 AM.

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