getopt_long 问题
zwch 2002-09-12 12:24:41 #include <stdio.h>
#include <getopt.h>
#include <string.h>
#include <stdlib.h>
#include <unistd.h>
static struct option main_long_options[] = {
{"help", no_argument, 0, 'h'},
{"type", required_argument, 0, 't'},
{0, 0, 0, 0}
};
int main(int argc,char * argv[])
{
char * str;
char c; //option
int option_index=0;
if(argc<1)
{
usage();
exit(0);
}
/
str=(char *)malloc(255);
c = getopt_long (argc, argv, "ht",
main_long_options, &option_index);
switch (c)
{
case 'h':
printf("some thing");
exit(1);
case 't':
if(optarg)
{
printf("some thing else");
}
break;
case default:
break;
}
}
./程序名 -t some
结果总是
(null)
请问为什么