请大神帮解释下这段代码,相干argc,argv的
请大神帮解释下这段代码,有关argc,argv的
void getparm(int argc,char *const argv[],int *port,int *slotnum)
{
char c;
*port = 10728;
*slotnum =32;//defalut
struct option my[]=
{
{"port",1,0,'p'},
{"num",1,0,'n'}
};
while((c=getopt_long(argc,argv,"p:n:dft",my,NULL))!=EOF)
{
switch(c)
{
case 'p':
*port = atoi(optarg);
break;
case 'n':
*slotnum = atoi(optarg);
break;
case 'd':
g_bDebug = true; //show the running info
break;
case 'f':
g_bFileRec = true;//record slot data
// std::cout<<"FLAG OPEN\n";
break;
case 't':
g_bTimeRec = true;
break; //time show;
default:
if(g_bDebug)
std::cout<<"parmer error"<<std::endl;
break;
}
}
}
主要是struct option那网上看了些资料实在看不懂,有能讲解打浅显易懂点的么。。谢谢啦!!
------解决思路----------------------
"p:n:dft",这个就是分析命令行选项,-p -n
类似 ls -l 中的 l
------解决思路----------------------
还有这么巧的事情,正好我在搞驱动练习的时候涉及到这个,今天来看了一下,哈哈正好看到了
void getparm(int argc,char *const argv[],int *port,int *slotnum)
{
char c;
*port = 10728;
*slotnum =32;//defalut
struct option my[]=
{
{"port",1,0,'p'},
{"num",1,0,'n'}
};
while((c=getopt_long(argc,argv,"p:n:dft",my,NULL))!=EOF)
{
switch(c)
{
case 'p':
*port = atoi(optarg);
break;
case 'n':
*slotnum = atoi(optarg);
break;
case 'd':
g_bDebug = true; //show the running info
break;
case 'f':
g_bFileRec = true;//record slot data
// std::cout<<"FLAG OPEN\n";
break;
case 't':
g_bTimeRec = true;
break; //time show;
default:
if(g_bDebug)
std::cout<<"parmer error"<<std::endl;
break;
}
}
}
主要是struct option那网上看了些资料实在看不懂,有能讲解打浅显易懂点的么。。谢谢啦!!
------解决思路----------------------
"p:n:dft",这个就是分析命令行选项,-p -n
类似 ls -l 中的 l
------解决思路----------------------
还有这么巧的事情,正好我在搞驱动练习的时候涉及到这个,今天来看了一下,哈哈正好看到了