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