//命令行参数使用。

来源:互联网 发布:cf占卜抽奖软件 编辑:程序博客网 时间:2024/06/11 14:01
//命令行参数使用。 
//将ComandLineArg.exe拷贝到C盘,
//cd c:\     
//ComandLineArg 10 20 max   // 正确用法
//ComandLineArg  x  // 参数不够,提示usage
//ComandLineArg 10 20 x // 参数x 不正确。 
//ComandLineArg 10 20 max min  // 参数多余,min不理会。




// 函数库stdlib中已经定义了,无需再定义 : 若重新定义后,提示 type error.
/* 
int max( int x, int y)
{
return (x>y? x:y);  
}


  int min( int x, int y)
  {
  return (x<=y? x:y);
  }
*/


/*


  #include <stdio.h>
  #include <stdlib.h>
  #include <string.h>
  
void main(int argc, char * argv[]) 
{
int a,b; 
char *operate_flag;
if (argc<4)
{
printf("Usage: ComandLineArg integer1 integer2 operate_flag \n");
exit(0);
}

 a=atoi(argv[1]);
 b=atoi(argv[2]);
 operate_flag=argv[3];
 
if(0==strcmp(operate_flag, "max"))
printf("The %s of %s and %s is : %d\n",argv[3],argv[1],argv[2],max(a,b));
else if(0==strcmp(operate_flag, "min"))
printf("The %s of %s and %s is : %d\n",argv[3],argv[1],argv[2],min(a,b));
else
printf("operate_flag should be max or min !");
}

 
*/
原创粉丝点击