C语言命令行参数问题,请高手帮忙

2024-12-26 08:32:21
推荐回答(3个)
回答1:

int main(int argc,char **argv)
{
int i;
printf("like ");
for(i=1;i {
if(i==4) printf("or ");
printf("%s ",argv[i]);
}
printf("\n");
return 0;
}

回答2:

应该符合要求吧

#include

int main(int argc, char *argv[]) {
if(argc<3) {
printf("at least input 2 arguments...\n");
return 0;
}
int i;
if(argc==3) {
printf("%s",argv[0]);
for(i=1;i printf(" %s",argv[i]);
}
printf("\n");
}
else {
printf("%s",argv[0]);
for(i=1;i printf(" %s",argv[i]);
}
printf(" or %s\n",argv[argc-1]);
}
return 0;
}

回答3:

//---------------------------------------------------------------------------

#include

int main(int argc, char* argv[])
{
int i;
printf("like\t");
for (i=1; i printf("%s\t",argv[i]);
}
printf("or\t%s\n",argv[argc-1]);
return 0;
}
//---------------------------------------------------------------------------