我正在使用 poptGetArgs 读取单个选项的多个值。但它总是将 null 作为返回值。我在下面发布了我的代码。如果有任何错误,请帮助我解决。
int main(int argc, char **argv)
{
char filename[ 128 ], symbol[32];
memset(filename, 0x0, 128);
memset(symbol, 0x0, 32);
struct poptOption opttable[] =
{
{ "file", 'f', POPT_ARG_STRING, filename, INPUT_NAME, "filenames to read", "list of files we need to read" },
{ "symbol", 'r', POPT_ARG_STRING, symbol, SYMBOL, "symbol to view", NULL },
{ NULL, 0, 0, NULL, 0 }
};
poptContext options_socket = poptGetContext( NULL, argc, ( const char **)argv, opttable, 0 );
int optionvalue(0);
while( optionvalue > -1 )
{
optionvalue = poptGetNextOpt( options_socket );
if(optionvalue == INPUT_NAME)
{
const char ** files = poptGetArgs( options_socket );
if( files == NULL )
{
printf("There was an error while reading input files\n");
}
}
else if( optionvalue == SYMBOL)
{
strcpy(symbol, poptGetOptArg( options_socket ));
printf("symbol you are giving as input is :%s, option value:%d\n", symbol, optionvalue);
}
}
return 0;
}