在命令行输入如下命令:
xcopy /s c:\ d:\,
各个参数如下:
参数1:命令字xcopy
参数2:字符串/s
参数3:字符串c:\
参数4: 字符串d:\
请编写一个参数解析程序,实现将命令行各个参数解析出来。
#include <string>
#include <iostream>
using namespace std;
void main(){
char s[1000],a[100][50];
int i=0,j,f=0,p=0,q=0,l;
gets(s);
l=strlen(s);
for(i=0;i<l;i++)
{
if(s[i]!=' '||f==1)
{
if(s[i]!='"')
{
a[p][q++]=s[i];
}else
{if(f==0)
f=1;
else
f=0;
}
}else
{
a[p][q]='"';
q=0;
}
}
a[p][q]='"';
cout<<p+1<<endl;
for(i=0;i<p+1;i++)
{ j=0;
while(a[i][j]!='"')
cout<<a[i][j++];
cout<<endl;
}
}