- 论坛徽章:
- 0
|
谁能说一下getopt函数的详细用法?
int main(int argc,char *argv[])
{
int i,query_type=0,query_flag=0;
char config_file[512];
char begin_time[20],end_time[20];
printf("USAGE: %s -c config_file[配置文件] -b begin_time[YYYY-MM-DD] -e end_time -t query_type[0:全部统计,1:业务统计,2:每天统计,3:用户数量统计] -f\n",argv[0]);
while ( (i = getopt( argc, argv, "c:b:e:t:f" )) != EOF ) {
switch( i ) {
case 'c':
strcpy(config_file,optarg );
break;
case 'b':
begin_time=str_to_time( optarg);
break;
case 'e':
end_time=str_to_time( optarg );
break;
case 't':
query_type = atoi(optarg);
break;
case 'f':
query_flag = 1;
break;
default:
printf("USAGE: %s -c config_file[配置文件] -b begin_time[YYYY-MM-DD] -e end_time -t query_type[0:全部统计,1:业务统计,2:每天统计,3:用户数量统计] -f\n",argv[0]);
break;
}
}
} |
|