Chinaunix首页 | 论坛 | 博客
  • 博客访问: 201441
  • 博文数量: 37
  • 博客积分: 0
  • 博客等级: 民兵
  • 技术积分: 375
  • 用 户 组: 普通用户
  • 注册时间: 2015-04-23 21:00
个人简介

潜心静气。。慢慢出成果

文章分类

全部博文(37)

文章存档

2018年(5)

2017年(6)

2016年(23)

2015年(3)

我的朋友

分类: C/C++

2015-04-23 21:31:18

经过自己的愚公移山的精神终于探明白了main的部分奥秘。分享给大家

Void mian (void)

int main(int argc,char *argv[])

int main(int argc,char **argv)

 

#include

#include

 

int main(int argc,char *argv[])

{

  char  s1[100];

  char  s2[100];

  char  s3[100];

 

  strcpy(s1,argv[0]);

  strcpy(s2,argv[1]);

  strcpy(s3,argv[2]);

  printf("s1=%s\n",s1);

  printf("s2=%s\n",s2);

  printf("s3=%s\n",s3);

 

  return 0;

}

 

int main(int argc,char **argv)

{

  char  s1[100];

  char  s2[100];

  char  s3[100];

 

  strcpy(s1,argv[0]);

  strcpy(s2,argv[1]);

  strcpy(s3,argv[2]);

  printf("s1=%s\n",s1);

  printf("s2=%s\n",s2);

  printf("s3=%s\n",s3);

 

  return 0;

}

经过gcc后编译生成a.out 缺省参数的结果

一摸一样的代码执行一样的结果。

./a.out  “11” “22”

s1=./a.out

s2=11

s3=22

所以mian会自动的检测参数个数。然后argv[0]作为命令。

所有的细节希望看客自己品悟了。

但是小可不明白。为什么不可以是int mian(int argc,int **argv)

测试后发现真的不可以,因为出来的永远是一堆我们看不懂的数字,不过如果想要数字,可以用字符转化

以下是例程供分析

#include

#include

#include

 

/*  the Parameter is : argv[0] for the order argv[1] for qrecode message */

/* the Parameter is : argv[2] for the qencode_x argv[3] for the qrencode_y */

 /* the Parameter is : argv[3] for the qencode_size                    */

 

//constchar*str1="";

const char *str2="\0";//the message of the qrencode

char *qrencode_x="\0";// x  coordiante

char *qrencode_y="\0";//y  coordiante

char *qrencode_size="\0";//the qrencode size

int x,y,size;/* x ,y ,size*/

/*limit the qrencode size is 164*/

int X_qrencode=164;

int Y_qrencode=164;

/* tranform the char to int */

int char_tranf_int(char * s)

{  

   int error;

   char str[10];

   error=strcpy(str,s);

   int num=strlen(str);

   int val;

   printf("num=%d\n",num);

   printf("str=%s\n",str);

   switch(num)

     {

      case 1 : val=(str[0]-48);break;

      case 2 : val=(str[0]-48)*10+(str[1]-48);break;

      case 3 : val=(str[0]-48)*100+(str[1]-48)*10+(str[2]-48);break;

      case 4:  val=(str[0]-48)*1000+(str[1]-48)*100+(str[2]-48)*10+(str[3]-48);break;

      default : printf("please check the x,y plane\n");break;

   }

   printf("val=%d\n",val);

   return val;

}

 

/* tranform the decimal num  to the round num          */

/*  for example if the  decimal num  >2.5 the result is 3  */

/*if the num <2.5 the result is 2                         */

 

int  floor(int nu)

{

   int num_floor;

 

   num_floor=(int)(nu+0.5);

   printf("num_floor=%d\n",num_floor);

   return num_floor;

}

 

int main(int argc, char **argv)

{

 

         QRcode *qrcode;

        

         str2=argv[1];

         qrencode_x=argv[2];

         qrencode_y=argv[3];

         //qrencode_size=argv[4];

         x=char_tranf_int(qrencode_x);

         y=char_tranf_int(qrencode_y);

         //size=char_tranf_int(qrencode_size);

         x=floor(x);

         y=floor(y);

         //size=floor(size);

         printf("x=%d,y=%d\n",x,y);

         printf("123\n");

 

         Fb_init();

 

         printf("fb init ok\n");

         /*str1*/

         /*qrcode = CreatQr(str1);

         Fb_QrDisp(300,300,qrcode);*/

 /*str2*/

  qrcode = CreatQr(str2);

 Fb_QrDisp(x,y,qrcode);

 

         return 0;

}

 

阅读(2359) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~