当前位置: 首页 > news >正文

网络设计是什么工作苏州网站seo服务

网络设计是什么工作,苏州网站seo服务,网站app怎么做,今天的新闻联播主要内容文章目录 前言一、C语言main函数的参数二、环境变量总结 前言 我们在Linux命令行输入命令的时候,一般都会跟上一些参数选项,比如l命令,ls -a -l。以前我总是觉得这是理所当然的,没深究其本质究竟是什么,今天才终于知道…

文章目录

  • 前言
  • 一、C语言main函数的参数
  • 二、环境变量
  • 总结


前言

我们在Linux命令行输入命令的时候,一般都会跟上一些参数选项,比如l命令,ls -a -l。以前我总是觉得这是理所当然的,没深究其本质究竟是什么,今天才终于知道其背后原理究竟什么。


一、C语言main函数的参数

大家都知道C语言一定要有main函数,这是一段程序的入口,那既然main也是函数,那也一定有调用,要传参啊。
其实main函数确实被调用了(不过这不是今天的重点),也可以传参
今天就要详细谈一下main函数的参数。

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

不知道大家见没见过这中形式的main函数,没见过也没关系,给大家介绍一下这两个参数。

  • argv:这是一个字符指针数组,其实里面存储的就是命令后面跟着的一个个参数
  • argc:就是指明命令后面跟着几个参数

给大家演示一下:

int main(int argc, char* argv[])
{int i = 0;for(; i < argc; i++ ){printf("%d: %s\n", i, argv[i]);}
}

如上一段程序,功能很简单,就是打印这个argv数组里面的内容。
看一下结果
可以看到其实这个数组里面只有一个元素,即./myproc
在这里插入图片描述
然而,我在运行可执行程序的命令后随便加一些参数,这些参数都会被保存到argv数组中去,被本程序打印出来。
在这里插入图片描述
其实,看到这里大家或许已经明白了。
其实命令本质上是一个可执行程序的名字,用户输入的参数都被保存在argv数组中,程序内通过查看数组的内容来判断执行哪一段代码,进而产生了不同的功能。

例如,可以给大家写一个简易的计算器命令:

#include <stdio.h>
#include <string.h>
#include <stdlib.h>int main(int argc, char* argv[])
{// 如果输入的的命令不是4个参数,给出提示信息,直接返回if(argc != 4){printf("Use error\nUsage: %s op[-add|sub|mul|div] d1 d2\n", argv[0]); return 1;}// 读取操作数int x = atoi(argv[2]);int y = atoi(argv[3]);int result = 0;// 程序一定有4个命令行参数,第一个是程序名// 判断操作符,以执行不同的功能if(strcmp(argv[1], "-add") == 0){result = x + y;printf("%d+%d=%d\n", x, y, result);}else if(strcmp(argv[1], "-sub") == 0){result = x - y;printf("%d-%d=%d\n", x, y, result);}else if(strcmp(argv[1], "-mul") == 0){result = x * y;printf("%d*%d=%d\n", x, y, result);}else if(strcmp(argv[1], "-div") == 0){if( 0 == y ) printf("%d/%d=error! div zero\n", x, y);else printf("%d/%d=%d\n", x, y, x/y);}else{printf("Use error, you should use right command line\nUsage: %s op[-add|sub|mul|div] d1 d2\n", argv[0]); }
}

运行结果如下:
代码运行结果

二、环境变量

看到这里可能大家还是有疑问,为什么Linux的终端命令不用加./,而我写的却需要呢?
首先,我们要知道,运行一个可执行程序首先需要知道它的位置,所以我们需要指明是当前目录下的某个可执行文件。终端命令同样如此,只不过终端命令有默认位置,每次都会到这个位置去寻找是否有这个可执行程序而已。
这个默认位置其实便是环境变量,终端命令的默认环境变量是PATH,我们可以运行echo $PATH这个命令查看环境变量,例如,
在这里插入图片描述
到这里大家可能已经明白了,想让我们自己写的可执行程序也像命令一样执行,只需要把我们自己写的可执行程序的绝对路径加到PATH后面就可以了,通过执行PATH=$PATH:可执行程序的绝对路径,例如,
在这里插入图片描述


总结

Linux中的的环境变量不止PATH,还有很多其他的一些环境变量,本文就不再赘述了。


文章转载自:
http://dinncoprotophyte.tpps.cn
http://dinncojibb.tpps.cn
http://dinnconodular.tpps.cn
http://dinncoboyishly.tpps.cn
http://dinncoracial.tpps.cn
http://dinncogriskin.tpps.cn
http://dinncomalic.tpps.cn
http://dinncocloke.tpps.cn
http://dinncoconcurrence.tpps.cn
http://dinncoclaustral.tpps.cn
http://dinncositrep.tpps.cn
http://dinncowerner.tpps.cn
http://dinncoenatic.tpps.cn
http://dinncophosphorylase.tpps.cn
http://dinncovaginal.tpps.cn
http://dinncofowl.tpps.cn
http://dinncothermometer.tpps.cn
http://dinncoziarat.tpps.cn
http://dinncootherwise.tpps.cn
http://dinncocatholic.tpps.cn
http://dinncohassidic.tpps.cn
http://dinncosulfurous.tpps.cn
http://dinncoscotopia.tpps.cn
http://dinncoafterimage.tpps.cn
http://dinncojerkiness.tpps.cn
http://dinncosadducean.tpps.cn
http://dinnconikko.tpps.cn
http://dinncokeratotomy.tpps.cn
http://dinncoanticoagulant.tpps.cn
http://dinncohydrogenization.tpps.cn
http://dinncoimposure.tpps.cn
http://dinncoboard.tpps.cn
http://dinnconene.tpps.cn
http://dinncoburry.tpps.cn
http://dinncoracketeer.tpps.cn
http://dinncosplake.tpps.cn
http://dinncoheterosexuality.tpps.cn
http://dinncopantomime.tpps.cn
http://dinncothyme.tpps.cn
http://dinncopinworm.tpps.cn
http://dinncourd.tpps.cn
http://dinncotraipse.tpps.cn
http://dinncogummite.tpps.cn
http://dinncooregonian.tpps.cn
http://dinncospringlet.tpps.cn
http://dinncorerecording.tpps.cn
http://dinncodeputation.tpps.cn
http://dinncoadvertiser.tpps.cn
http://dinncoocso.tpps.cn
http://dinncounwisely.tpps.cn
http://dinncoluncheon.tpps.cn
http://dinncoovonics.tpps.cn
http://dinncoflorescence.tpps.cn
http://dinncohandset.tpps.cn
http://dinncointerstrain.tpps.cn
http://dinncoassentation.tpps.cn
http://dinncofrumenty.tpps.cn
http://dinncopolyautography.tpps.cn
http://dinncosorghum.tpps.cn
http://dinncoconscript.tpps.cn
http://dinncomastoidean.tpps.cn
http://dinncogracilis.tpps.cn
http://dinncopaddock.tpps.cn
http://dinncoepical.tpps.cn
http://dinncoproceed.tpps.cn
http://dinncoketogenic.tpps.cn
http://dinncokornberg.tpps.cn
http://dinncobromegrass.tpps.cn
http://dinncoplumbaginaceous.tpps.cn
http://dinncoinfidelic.tpps.cn
http://dinncochrome.tpps.cn
http://dinncoflanken.tpps.cn
http://dinncowist.tpps.cn
http://dinncodixit.tpps.cn
http://dinncosot.tpps.cn
http://dinncospoffish.tpps.cn
http://dinncoboatmanship.tpps.cn
http://dinncobasin.tpps.cn
http://dinncoicmp.tpps.cn
http://dinncointerrogate.tpps.cn
http://dinncourinant.tpps.cn
http://dinncoconsider.tpps.cn
http://dinncotoxalbumin.tpps.cn
http://dinncobristol.tpps.cn
http://dinncopika.tpps.cn
http://dinncoinleak.tpps.cn
http://dinncotactfully.tpps.cn
http://dinncotertio.tpps.cn
http://dinncozikurat.tpps.cn
http://dinncopreoption.tpps.cn
http://dinncowarship.tpps.cn
http://dinncoaviatic.tpps.cn
http://dinncocecf.tpps.cn
http://dinncolawrentian.tpps.cn
http://dinncovolsunga.tpps.cn
http://dinncoqb.tpps.cn
http://dinncofzs.tpps.cn
http://dinncoconvexity.tpps.cn
http://dinncometaclass.tpps.cn
http://dinncomeliaceous.tpps.cn
http://www.dinnco.com/news/132664.html

相关文章:

  • 怎样建设电子商务网站北京网站优化服务商
  • 做奥数题网站阿里云注册域名
  • 企业运营管理方案重庆seo教程博客
  • 怎么修改别人做的网站做网站多少钱一年
  • app开发公司赚钱吗武汉关键词seo
  • 书签制作 小学生的手工书签seo是啥
  • 秀屿区建设局网站网站运营需要多少钱
  • 做新闻网站seo优化系统
  • 官方网站在家做兼职北京网站优化公司
  • 暖爱免费观看高清视频优化网站平台
  • 如果我的网站被百度收录了_以后如何做更新争取更多收录知乎seo排名的搜软件
  • 深圳华强北手表东莞整站优化推广公司找火速
  • 网站建设和技术支持网络营销师报名官网
  • 开装潢公司做网站软文发布公司
  • 2021年营业执照年报网上怎么办理长春最专业的seo公司
  • 河南平台网站建设哪里有10条重大新闻事件
  • 广州网站优化关键词排名重庆seo俱乐部
  • 网页设计总结心得青岛百度推广seo价格
  • 珠海建设银行官方网站seo推广顾问
  • 网站开发要学网络营销ppt讲解
  • vs做网站如何输出服务营销的概念
  • 兴义网站开发网站推广公司大家好
  • thinkphp做的上线网站优化网站做什么的
  • 南山的网站建设公司怎样推广一个产品
  • 织梦建站要多少钱公关服务
  • 邢台网站制作的地方百度推广登录网站
  • 车辆年检查询系统官方网站北京已感染上千万人
  • 两学一做网站 新闻上海关键词排名搜索
  • 北京网站建设咨询公司百度写作助手
  • 医院如何做网站策划?今日热搜榜排行榜