DIR处理命令数组赋省参数*/if

C语言编写的程序中也可以实现,灵活地运用命令行参数效地程序的运行效率,收到事倍的效果。C语言中有命令行参数涉及到程序的主函数main(int argc,char *argv[]这样两个参数,其中,int argc表示命令行参数的个数(包括可执行程序名本身),char *每个参数的具体内容,argv[0]为命令行执行程序名本身,[1]为命令行中第二个参数的内容,依次类推。如下例输出命令行参数的个数及参数的内容:

main (int argc,char *argv[],I=0;while(argc>=1)

命令行参数用的最多还是在诸如DIR A:等之类带有盘符、路径或件名令行中,所以说灵活处理这一类参数才能有效地提高程序的运行效果。譬如DIR命令,其后可以是盘符,可以是路径,也可以是文件名,如何区一参数呢?请看下例(此模拟DIR命令,程序要求在命令行输入一个参数:盘符或路径或文件名或参数多于一个都将取默认的参数“*.*”)。

\*--------------------

功能:模拟DIR命令进行处理命令行参数

--------------------*/#include#include#include#incdeint j,num=0;char ss[20],path[50],path2[50];

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

{struct ffblk f;int done;if(argc==2)  /*取命令行参数到数组中*/stcpy(ss,argv[1]);elsestrcpy(ss,″*.*″); /*给数组赋省参数*/if (((ss[strlen(ss)-1]==′\\′||((ss[strlen(ss)-1]==‘:‘))strcat(ss,″*.*″); /*若参数为路径或盘符,则加上″*.*″ */getcwd(pat1,50); /*取当前径*/if (chdir(ss)==0)
/*判断参数是路径*/strcat(ss,\\*.*); /*若路径末没有带\,则加上*.* */chdir(path1); /*恢复原来路径*/

http://read.qidian.com/BookReader/3288385,62656002.aspx

http://read.qidian.com/BookReader/3288385,62656046.aspx

http://read.qidian.com/BookReader/3288385,62656134.aspx

http://read.qidian.com/BookReader/3288385,62656192.aspx

http://read.qidian.com/BookReader/3288385,62656239.aspx

http://read.qidian.com/BookReader/3288385,62656268.aspx

http://read.qidian.com/BookReader/3288385,62656304.aspx

http://read.qidian.com/BookReader/3288385,62656344.aspx

http://read.qidian.com/BookReader/3288385,62656395.aspx

http://read.qidian.com/BookReader/3288385,62656460.aspx

http://read.qidian.com/BookReader/3288385,62656691.aspx

http://read.qidian.com/BookReader/3288385,62656747.aspx

http://read.qidian.com/BookReader/3288385,62656790.aspx

http://read.qidian.com/BookReader/3288385,62657292.aspx

http://read.qidian.com/BookReader/3288385,62657317.aspx

http://read.qidian.com/BookReader/3288385,62657375.aspx

http://read.qidian.com/BookReader/3288385,62657583.aspx

http://read.qidian.com/BookReader/3288385,62657637.aspx

http://read.qidian.com/BookReader/3288385,62657722.aspx

http://read.qidian.com/BookReader/3288385,62657767.aspx

http://read.qidian.com/BookReader/3288385,62657820.aspx

http://read.qidian.com/BookReader/3288385,62657868.aspx

http://read.qidian.com/BookReader/3288385,62657903.aspx

http://read.qidian.com/BookReader/3288385,62657966.aspx

http://read.qidian.com/BookReader/3288385,62658025.aspx

http://read.qidian.com/BookReader/3288385,62658073.aspx

http://read.qidian.com/BookReader/3288385,62658101.aspx

http://read.qidian.com/BookReader/3288385,62658132.aspx

http://read.qidian.com/BookReader/3288385,62658175.aspx

http://read.qidian.com/BookReader/3288385,62658207.aspx

http://read.qidian.com/BookReader/3288385,62658250.aspx

http://read.qidian.com/BookReader/3288385,62658272.aspx

http://read.qidian.com/BookReader/3288385,62658300.aspx

http://read.qidian.com/BookReader/3288385,62658326.aspx

http://read.qidian.com/BookReader/3288385,62658346.aspx

http://read.qidian.com/BookReader/3288385,62658379.aspx

http://read.qidian.com/BookReader/3288385,62658417.aspx

http://read.qidian.com/BookReader/3288385,62658453.aspx

http://read.qidian.com/BookReader/3288385,62658480.aspx

http://read.qidian.com/BookReader/3288385,62658510.aspx

http://read.qidian.com/BookReader/3288385,62658536.aspx

http://read.qidian.com/BookReader/3288385,62658565.aspx

http://read.qidian.com/BookReader/3288385,62658602.aspx

http://read.qidian.com/BookReader/3288385,62658627.aspx

http://read.qidian.com/BookReader/3288385,62658664.aspx

http://read.qidian.com/BookReader/3288385,62658710.aspx

http://read.qidian.com/BookReader/3288385,62658748.aspx

http://read.qidian.com/BookReader/3288385,62658772.aspx

http://read.qidian.com/BookReader/3288385,62658816.aspx

http://read.qidian.com/BookReader/3288385,62658901.aspx

http://read.qidian.com/BookReader/3288385,62658933.aspx

http://read.qidian.com/BookReader/3288385,62658968.aspx

http://read.qidian.com/BookReader/3288385,62659018.aspx

http://read.qidian.com/BookReader/3288385,62659036.aspx

http://read.qidian.com/BookReader/3288385,62659074.aspx

http://read.qidian.com/BookReader/3288385,62659104.aspx

http://read.qidian.com/BookReader/3288385,62659124.aspx

http://read.qidian.com/BookReader/3288385,62659191.aspx

http://read.qidian.com/BookReader/3288385,62659236.aspx

http://read.qidian.com/BookReader/3288385,62659301.aspx

http://read.qidian.com/BookReader/3288385,62659338.aspx

http://read.qidian.com/BookReader/3288385,62659362.aspx

http://read.qidian.com/BookReader/3288385,62659437.aspx

http://read.qidian.com/BookReader/3288385,62659484.aspx

http://read.qidian.com/BookReader/3288385,62659558.aspx

http://read.qidian.com/BookReader/3288385,62659618.aspx

http://read.qidian.com/BookReader/3288385,62659660.aspx

http://read.qidian.com/BookReader/3288385,62659687.aspx

http://read.qidian.com/BookReader/3288385,62659714.aspx

http://read.qidian.com/BookReader/3288385,62660892.aspx

http://read.qidian.com/BookReader/3288385,62660900.aspx

http://read.qidian.com/BookReader/3288385,62660928.aspx

http://read.qidian.com/BookReader/3288385,62660944.aspx

http://read.qidian.com/BookReader/3288385,62660957.aspx

http://read.qidian.com/BookReader/3288385,62660967.aspx

http://read.qidian.com/BookReader/3288385,62660988.aspx

http://read.qidian.com/BookReader/3288385,62661005.aspx

http://read.qidian.com/BookReader/3288385,62661025.aspx

http://read.qidian.com/BookReader/3288385,62661050.aspx

http://read.qidian.com/BookReader/3288385,62661071.aspx

http://read.qidian.com/BookReader/3288385,62661086.aspx

http://read.qidian.com/BookReader/3288385,62661105.aspx

http://read.qidian.com/BookReader/3288385,62661122.aspx

http://read.qidian.com/BookReader/3288385,62661132.aspx

http://read.qidian.com/BookReader/3288385,62665474.aspx

http://read.qidian.com/BookReader/3288385,62665500.aspx

http://read.qidian.com/BookReader/3288385,62665531.aspx

http://read.qidian.com/BookReader/3288385,62665569.aspx

http://read.qidian.com/BookReader/3288385,62665583.aspx

http://read.qidian.com/BookReader/3288385,62665632.aspx

http://read.qidian.com/BookReader/3288385,62665671.aspx

http://read.qidian.com/BookReader/3288385,62665761.aspx

http://read.qidian.com/BookReader/3288385,62665858.aspx

http://read.qidian.com/BookReader/3288385,62665882.aspx

http://read.qidian.com/BookReader/3288385,62665925.aspx

http://read.qidian.com/BookReader/3288385,62665986.aspx

http://read.qidian.com/BookReader/3288385,62666057.aspx

http://read.qidian.com/BookReader/3288385,62666108.aspx

http://read.qidian.com/BookReader/3288385,62666120.aspx

http://read.qidian.com/BookReader/3288385,62666130.aspx

http://read.qidian.com/BookReader/3288385,62666147.aspx

http://read.qidian.com/BookReader/3288385,62666160.aspx

http://read.qidian.com/BookReader/3288385,62666176.aspx

http://read.qidian.com/BookReader/3288385,62666197.aspx

http://read.qidian.com/BookReader/3288385,62666233.aspx

http://read.qidian.com/BookReader/3288385,62666408.aspx

http://read.qidian.com/BookReader/3288385,62666425.aspx

http://read.qidian.com/BookReader/3288385,62666469.aspx

http://read.qidian.com/BookReader/3288385,62666509.aspx

http://read.qidian.com/BookReader/3288385,62666526.aspx

http://read.qidian.com/BookReader/3288385,62666546.aspx

http://read.qidian.com/BookReader/3288385,62666561.aspx

http://read.qidian.com/BookReader/3288385,62666585.aspx

http://read.qidian.com/BookReader/3288385,62666692.aspx

http://read.qidian.com/BookReader/3288385,62666798.aspx

http://read.qidian.com/BookReader/3288385,62666871.aspx

http://read.qidian.com/BookReader/3288385,62666923.aspx

http://read.qidian.com/BookReader/3288385,62666991.aspx

http://read.qidian.com/BookReader/3288385,62667045.aspx

http://read.qidian.com/BookReader/3288385,62667090.aspx

http://read.qidian.com/BookReader/3288385,62667113.aspx

http://read.qidian.com/BookReader/3288385,62667168.aspx

http://read.qidian.com/BookReader/3288385,62667212.aspx

http://read.qidian.com/BookReader/3288385,62667244.aspx

http://read.qidian.com/BookReader/3288385,62667292.aspx

http://read.qidian.com/BookReader/3288385,62667313.aspx

http://read.qidian.com/BookReader/3288385,62667348.aspx

http://read.qidian.com/BookReader/3288385,62667459.aspx

http://read.qidian.com/BookReader/3288385,62667522.aspx

http://read.qidian.com/BookReader/3288385,62667538.aspx

http://read.qidian.com/BookReader/3288385,62667583.aspx

http://read.qidian.com/BookReader/3288385,62667618.aspx

http://read.qidian.com/BookReader/3288385,62667672.aspx

http://read.qidian.com/BookReader/3288385,62667697.aspx

http://read.qidian.com/BookReader/3288385,62667750.aspx

http://read.qidian.com/BookReader/3288385,62667813.aspx

http://read.qidian.com/BookReader/3288385,62667876.aspx

http://read.qidian.com/BookReader/3288385,62667918.aspx

http://read.qidian.com/BookReader/3288385,62667956.aspx

http://read.qidian.com/BookReader/3288385,62667982.aspx

http://read.qidian.com/BookReader/3288385,62667996.aspx

http://read.qidian.com/BookReader/3288385,62668016.aspx

http://read.qidian.com/BookReader/3288385,62668076.aspx

http://read.qidian.com/BookReader/3288385,62668140.aspx

http://read.qidian.com/BookReader/3288385,62668200.aspx

http://read.qidian.com/BookReader/3288385,62669157.aspx

http://read.qidian.com/BookReader/3288385,62669306.aspx

http://read.qidian.com/BookReader/3288385,62669546.aspx

http://read.qidian.com/BookReader/3288385,62669873.aspx

http://read.qidian.com/BookReader/3288385,62670087.aspx

http://read.qidian.com/BookReader/3288385,62670092.aspx

http://read.qidian.com/BookReader/3288385,62670096.aspx

http://read.qidian.com/BookReader/3288385,62670104.aspx

http://read.qidian.com/BookReader/3288385,62670401.aspx

http://read.qidian.com/BookReader/3288385,62671547.aspx

http://read.qidian.com/BookReader/3288385,62671659.aspx

http://read.qidian.com/BookReader/3288385,62671664.aspx

http://read.qidian.com/BookReader/3288385,62674376.aspx

http://read.qidian.com/BookReader/3288385,62674380.aspx

http://read.qidian.com/BookReader/3288385,62674393.aspx

http://read.qidian.com/BookReader/3288385,62674401.aspx

http://read.qidian.com/BookReader/3288385,62674516.aspx

http://read.qidian.com/BookReader/3288385,62674526.aspx

http://read.qidian.com/BookReader/3288385,62674528.aspx

http://read.qidian.com/BookReader/3288385,62674611.aspx

http://read.qidian.com/BookReader/3288385,62674620.aspx

http://read.qidian.com/BookReader/3288385,62674690.aspx

http://read.qidian.com/BookReader/3288385,62674697.aspx

http://read.qidian.com/BookReader/3288385,62675002.aspx

http://read.qidian.com/BookReader/3288385,62675012.aspx

http://read.qidian.com/BookReader/3288385,62675039.aspx

http://read.qidian.com/BookReader/3288385,62675223.aspx

http://read.qidian.com/BookReader/3288385,62675226.aspx

http://read.qidian.com/BookReader/3288385,62675231.aspx

http://read.qidian.com/BookReader/3288385,62675234.aspx

http://read.qidian.com/BookReader/3288385,62675381.aspx

http://read.qidian.com/BookReader/3288385,62675403.aspx

http://read.qidian.com/BookReader/3288385,62675507.aspx

http://read.qidian.com/BookReader/3288385,62675703.aspx

http://read.qidian.com/BookReader/3288385,62675708.aspx

http://read.qidian.com/BookReader/3288385,62675752.aspx

http://read.qidian.com/BookReader/3288385,62675843.aspx

http://read.qidian.com/BookReader/3288385,62675856.aspx

http://read.qidian.com/BookReader/3288385,62675870.aspx

http://read.qidian.com/BookReader/3288385,62675874.aspx

http://read.qidian.com/BookReader/3288385,62675882.aspx

http://read.qidian.com/BookReader/3288385,62675925.aspx

http://read.qidian.com/BookReader/3288385,62675940.aspx

http://read.qidian.com/BookReader/3288385,62675981.aspx

http://read.qidian.com/BookReader/3288385,62675998.aspx

http://read.qidian.com/BookReader/3288385,62676004.aspx

http://read.qidian.com/BookReader/3288385,62676011.aspx

http://read.qidian.com/BookReader/3288385,62676044.aspx

http://read.qidian.com/BookReader/3288385,62676056.aspx

http://read.qidian.com/BookReader/3288385,62676071.aspx

http://read.qidian.com/BookReader/3288385,62676078.aspx

http://read.qidian.com/BookReader/3288385,62676088.aspx

http://read.qidian.com/BookReader/3288385,62676106.aspx

http://read.qidian.com/BookReader/3288385,62676194.aspx

http://read.qidian.com/BookReader/3288385,62676238.aspx

http://read.qidian.com/BookReader/3288385,62676293.aspx

http://read.qidian.com/BookReader/3288385,62676380.aspx

http://read.qidian.com/BookReader/3288385,62676503.aspx

http://read.qidian.com/BookReader/3288385,62676518.aspx

http://read.qidian.com/BookReader/3288385,62676527.aspx

http://read.qidian.com/BookReader/3288385,62676537.aspx

http://read.qidian.com/BookReader/3288385,62676638.aspx

http://read.qidian.com/BookReader/3288385,62676672.aspx

http://read.qidian.com/BookReader/3288385,62676691.aspx

http://read.qidian.com/BookReader/3288385,62676707.aspx

http://read.qidian.com/BookReader/3288385,62676843.aspx

http://read.qidian.com/BookReader/3288385,62676855.aspx

http://read.qidian.com/BookReader/3288385,62677197.aspx

http://read.qidian.com/BookReader/3288385,62677254.aspx

http://read.qidian.com/BookReader/3288385,62677269.aspx

http://read.qidian.com/BookReader/3288385,62677346.aspx

http://read.qidian.com/BookReader/3288385,62677451.aspx

http://read.qidian.com/BookReader/3288385,62677464.aspx

http://read.qidian.com/BookReader/3288385,62677480.aspx

http://read.qidian.com/BookReader/3288385,62677488.aspx

http://read.qidian.com/BookReader/3288385,62677522.aspx

http://read.qidian.com/BookReader/3288385,62677551.aspx

http://read.qidian.com/BookReader/3288385,62677569.aspx

http://read.qidian.com/BookReader/3288385,62677623.aspx

http://read.qidian.com/BookReader/3288385,62677674.aspx

http://read.qidian.com/BookReader/3288385,62677677.aspx

http://read.qidian.com/BookReader/3288385,62677694.aspx

http://read.qidian.com/BookReader/3288385,62677700.aspx

http://read.qidian.com/BookReader/3288385,62677708.aspx

http://read.qidian.com/BookReader/3288385,62677716.aspx

http://read.qidian.com/BookReader/3288385,62677818.aspx

http://read.qidian.com/BookReader/3288385,62677908.aspx

http://read.qidian.com/BookReader/3288385,62678027.aspx

http://read.qidian.com/BookReader/3288385,62678219.aspx

http://read.qidian.com/BookReader/3288385,62678249.aspx

http://read.qidian.com/BookReader/3288385,62678279.aspx

http://read.qidian.com/BookReader/3288385,62678318.aspx

http://read.qidian.com/BookReader/3288385,62678530.aspx

http://read.qidian.com/BookReader/3288385,62678618.aspx

http://read.qidian.com/BookReader/3288385,62678793.aspx

http://read.qidian.com/BookReader/3288385,62383610.aspx

时间: 2024-10-05 18:46:07

DIR处理命令数组赋省参数*/if的相关文章

数组与指针——参数

引入: #include <stdio.h> #include <stdlib.h> void fun(char **q) { exit; } void main() { char **p,a[6][8]; p = a; fun(a); } 编译不能通过! ERROR:不能将"char (*)[8]"类型的值分配到"char **"类型的实体. ERROR:"char (*)[8]"类型和"char **&quo

Linux挂载命令mount用法及参数详解

Linux挂载命令mount用法及参数详解 导读 mount是Linux下的一个命令,它可以将分区挂接到Linux的一个文件夹下,从而将分区和该目录联系起来,因此我们只要访问这个文件夹,就相当于访问该分区了. 挂接命令(mount) 首先,介绍一下挂接(mount)命令的使用方法,mount命令参数非常多,这里主要讲一下今天我们要用到的. 命令格式:mount [-t vfstype] [-o options] device dir 1.-t vfstype 指定文件系统的类型,通常不必指定,m

useradd命令中的-d参数不好用

 OS: Red Hat Enterprise Linux Server release 7.0 (Maipo) 目前对linux系统了解不是很多.一些操作保留浓重的windows习惯. 现在/home被我当作了仓库使用,我给它分配了很大的空间,并且塞了很多文件和目录在里面.这样我觉得如果多个用户的主目录散落在/home目录中的话,会是一件很蛋疼的事情. 所以我决定把所有的用户目录放置到/home/myusers下. useradd命令中的-d参数可以后接目录,于是输入如下命令: [[email

C++数组作为函数参数的几个问题(转)

本文需要解决C++中关于数组的2个问题:1. 数组作为函数参数,传值还是传址?2. 函数参数中的数组元素个数能否确定? 先看下面的代码. #include <iostream> using namespace std; void testArrayArg(int a[]) { cout << endl; cout << "in func..." << endl; cout << "array address: &qu

把数组中的n个元素的值分别扩大5倍,要求数组名作为参数。

通过把数组名作为参数传递,实际上是把数组的地址传递给形式参数.这样在被调用函数中就可以对整个数组进行操作了,将数组名作为参数传递,调用函数和被调用函数都是对占同一块内存单元的数组进行操作. #include<stdio.h> #define N 10 void MulArray1(int *x,int n);//数组名作为参数的函数原型 void MulArray2(int *aPtr,int n);//指针作为参数的函数原型 void main() { int a[N]={1,2,3,4,5

编程题:用一组数组做函数参数来实现,输入两个数,输出其中最大数

#include<stdio.h> float max(float x,float y) { float z; if(x>y)z=x; else z=y; return z; } void main() { float a[2],c; scanf("%f,%f",&a[0],&a[1]); c=max(a[0],a[1]); printf("%f,%f,the max is %f\n",a[0],a[1],c); } 编程题:用一组

C语言中数组名作为参数进行函数传递

用数组名作函数参数与用数组元素作实参有几点不同. 1) 用数组元素作实参时,只要数组类型和函数的形参变量的类型一致,那么作为下标变量的数组元素的类型也和函数形参变量的类型是一致的.因此,并不要求函数的形参也是下标变量.换句话说,对数组元素的处理是按普通变量对待的.用数组名作函数参数时,则要求形参和相对应的实参都必须是类型相同的数组,都必须有明确的数组说明.当形参和实参二者不一致时,即会发生错误. 2) 在普通变量或下标变量作函数参数时,形参变量和实参变量是由编译系统分配的两个不同的内存单元.在函

C语言--- 高级指针2(结构体指针,数组作为函数参数)

一.结构体指针 1. 什么是结构体指针?指向结构体变量的指针     结构体:     typedef  struct stu{                          char name[20];                          char sex;                          int age;                    }Student;     Student stu1 = {"zhangsan",'m',23};  

将一段含有0的字符数组赋给string

string有个成员函数,assign() 可以这样: 1 string str; 2 str.assign(temp, sizeof(temp)); 将一段含有0的字符数组赋给string,布布扣,bubuko.com