[问题]刚开始学就遇到问题了(刚发完就发现自己错了,愚蠢!!!)

软件和网站开发以及相关技术探讨
回复
pwsxp
帖子: 76
注册时间: 2007-09-19 22:30
来自: Shanghai

[问题]刚开始学就遇到问题了(刚发完就发现自己错了,愚蠢!!!)

#1

帖子 pwsxp » 2007-10-11 20:48

以下是我照LINUX应用程序开发指南:使用GTK+ GNOME库 第二章例子做得(才第二章阿)就遇到问题了
即使我命令带了参数,args始终是NULL,不解阿,请教了
#include <gnome.h>

struct poptOption options[] = {
{
"greet",
'g',
POPT_ARG_NONE,
FALSE, <-- 这必须给个变量,因为POPT_ARG_NONE是个开关值,如果开了,-g 则为TRUE,否则为FALSE
0,
"Say hello to specific people listed on the command line",
NULL
},
{
NULL,
'\0',
0,
NULL,
0,
NULL,
NULL
}
};

static char* PACKAGE = "base4";
static char* VERSION = "0.4";
static char* GNOMELOCALEDIR = "~/learning";
int main (int argc, char *argv[])
{
GtkWidget *app = NULL;
poptContext pctx;
char** args ;
bindtextdomain(PACKAGE, GNOMELOCALEDIR);
textdomain(PACKAGE);

gnome_init_with_popt_table(PACKAGE, VERSION, argc, argv, options, 0, &pctx);


args = poptGetArgs(pctx);
if (args ==NULL) {
g_error("args is null");
}
poptFreeContext(pctx);
gtk_main ();
return 0;
}
xiao-ye@xiao-ye-laptop:~/learning$ ./base4

** ERROR **: args is null
aborting...
忽略 (core dumped)
xiao-ye@xiao-ye-laptop:~/learning$ ./base4 -g

** ERROR **: args is null
aborting...
忽略 (core dumped)
头像
windwiny
帖子: 2254
注册时间: 2007-03-13 17:26

#2

帖子 windwiny » 2007-10-11 21:33

不要用这种简写吧,,一个一个值的写。。 万一顺序错了你都不知道
回复