码迷,mamicode.com
首页 > 其他好文 > 详细

实验一 命令解释程序的编写

时间:2015-06-25 19:30:40      阅读:123      评论:0      收藏:0      [点我收藏+]

标签:

一、目的和要求

1. 实验目的

(1)掌握命令解释程序的原理;

(2)掌握简单的DOS调用方法;

(3)掌握C语言编程初步。

2.实验要求

编写类似于DOS,UNIX的命令行解释程序

(1)自行定义系统提示符

(2)自定义命令集(8-10个)

(3)用户输入HELP以查找命令的帮助

(4)列出命令的功能,区分内部还是外部命令

(5)用户输入QUIT退出

(6)内部命令有dir, cd, md, rd, cls, date, time, ren, copy等。

二、实验内容

根据教师指定的实验课题,完成设计、编码、测试工作。

、实验环境

1.PC微机

2.Windows 操作系统

3.C/C++程序开发集成环境

四、实验原理及核心算法参考程序段

 1 #include<stdio.h>
 2 #include<string.h>
 3 void main() /*主函数*/
 4 {
 5 char *b[11]={"dir","cd","md","rd","cls","date","time","ren","copy","help", "quit"}; /*指针数组存储关键字*/
 6 int pan(char ch1[],char *j[11]);
 7 char a[10],*p=a;
 8 printf("Welcome.........\nPleas enter a command!\nEnter ‘quit‘ to quit.\nFor help,Enter ‘help‘.\n");
 9 c1: printf("c:\>$");
10 scanf("%s",a);
11 pan(p,b); /*函数调用*/
12 if(strcmp(a,b[10])!=0) /*比较输入的字符串是否quit结束命令*/ goto c1;
13 else printf("out of work!!\n");
14 }
15 int pan(char ch1[],char *j[11]) /*子函数*/
16 {
17 int i;
18 for( i=0;i<11;i++)
19 if(strcmp(ch1,j[i])==0) /*比较输入的字符串与数组的关键字是否相等*/
20 {
21 switch(i)
22 {
23 case 0:printf("command name is dir.\nIt‘s function is list file.\nIt‘s an internal command.\nVolume in drive K gas no label.\nVolume Serial Number is 60F0-6C24\n\n");break;
24 case 1:printf("command name is cd.\nIt‘s function is change directory.\nIt‘s an internal command.\n");break;
25 case 2:printf("command name is md.\nIt‘s function is creat a new directory.\nIt‘s an internal command.\n");break;
26 case 3:printf("command name is rd.\nIt‘s function is delete a directory which is empty.\nIt‘s an internal command.\n");break;
27 case 4:printf("command name is cls.\nIt‘s function is clean screen\nIt‘s an internal command.\n");break;
28 case 5:printf("command name is date.\nIt‘s function is show date.\nIt‘s an internal command.\n");break;
29 case 6:printf("command name is time.\nIt‘s function is shio time.\nIt‘s an internal command.\n");break;
30 case 7:printf("command name is ren.\nIt‘s function is rename a file.\nIt‘s an internal command.\n");break;
31 case 8:printf("command name is copy.\nIt‘s function is copy files.\nIt‘s an internal command.\n");break;
32 case 9:printf("dir\tcd\tmd\trd\tcls\ndate\ttime\tren\tcopy\nEnter \" quit\" to quit this program!!\n");break;
33 case 10:printf("Thanks for using it,bye!!\n");break;
34 }
35 return 1;}
36 printf("No this one!!\nNot a internal commal.\n");return0;
37 }

 

五  运行结果

技术分享

 

技术分享

 

心得:

这个学期第一次做的实验,不是很好,很多东西不是很懂。

技术分享

实验一 命令解释程序的编写

标签:

原文地址:http://www.cnblogs.com/leib123/p/4600672.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!