c语言微型命令解释程序,实验1-命令解释程序

#includevoid main()

{

int i,num;

char a[10],b[50],c[50],d[50],e[50],f[50];

char sjs[6][20]={"dir","cop","era","dat","tim","end"};

..

while(1)

{

printf("******************************\n"); printf("*dir:List File*\n"); printf("*cop:Copy File*\n"); printf("*era:Delete File*\n"); printf("*dat:Date*\n");

printf("*tim:Time*\n");

printf("*end:Quit*\n"); printf("******************************\n"); printf("******************************\n"); printf("Please Input b:\n"); scanf("%s",&a);

for(i=0;i<=6;i++)

{

if(!strcmp(a,sjs[i]))

{

num=i; break; num=7;

}

}

strcpy(b,"");

strcpy(c,"");

strcpy(d,""); switch(num)

{

case 0:

strcpy(b,"dir");break; case 1:

case 2:

printf("Please Input Source File:"); scanf("%s",&e);

printf("\nPlease Input Destination:"); scanf("%s",&c);

strcat(b,"copy");

strcat(b,e); strcat(b," "); strcat(b,c); break;

printf("Please Input Delete File:"); scanf("%s",&d);

strcat(b,"del"); strcat(b,d); break;

case 3:printf("Please Input String Date:"); scanf("%s",&e);

strcat(b,"Date ");

printf("Data:%s",e); break;

case 4:printf("Please Input Tim:");

scanf("%s",&f);

strcat(b,"Time ");

printf("Tim:%s",f); break;

case 5:

default:

}

printf(" 退出!! \n");exit(0);

printf("Err Command,Input Command Again!\n");

..

if(num>=0&&num<=5) system(b);

}

}

五、调试过程

1. 在写程序的过程中始终出现错误,忘记写头文件。

2. 在建立 txt 文档时,不需要后缀名,系统会默认txt 类型。六、实验结果及分析

本次实验依次实现了列出当前目录、拷贝文件、删除文件、显示日期、显示时间、结束退出等功能。如下图所示:

七、总结

1. 在程序中所用到的系统函数必须写上头文件。

2. 通过编程也了解了系统函数的一些功能,加深了对它的了解。

3. 在调试过程中,难免会出现错误,要耐心查找错误源。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值