实验一
实验一 命令解释程序的编写
一、目的和要求
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++程序开发集成环境
四、实验原理及核心算法参考程序段
显示程序提示信息;
While(1)
{ 显示提示符;
接收键盘的字符串;
判断是否quit程序退出指令,是则退出;
判断是否内部命令,并给出相应的信息,否则给出错误信息;
}
显示退出程序信息;
实验内容:
#include<stdio.h>
#include<string.h>
void main()
{
char*b[1]={"dir","cd","md","rd","cls","date","time","ren","copy","help","quit"};
int pan(char ch1[],char*j[11];
char a[10],*p=a;
printf("Welcome\nPlease enter a command!\nEnter 'quit' to quit\nFor help,Enter'help'\n");
c1: printf("c:\>$");
scanf("%s",a);
pan(p,b);
if(strcmp(a,b[10]!=0)
goto c1;
else printf("out of work!\n");
}
int pan ch1[],char*j[11])
{
int i;
for(i=0;i<=11;i++)
if(strcmp(ch 1,j[i]==0)
{
switch(i)
{
case 0:printf("Command name is dir.\nIt's function is list file.\nIt's an internal command.\nVolume in drive K gas no labe.\nVolume Serial Number is 60F0-6C24n\n");break;
case 1:printf("Command name is cd.t's function is list file.\nIt's an internal command.\nVolume in drive K gas no labe.\nVolume Serial Number is 60F0-6C24n\n");break;
case 2:printf("Command name is md.\nIt's function is list file.\nIt's an internal command.\nVolume in drive K gas no labe.\nVolume Serial Number is 60F0-6C24n\n");break;
case 3printf("Command name is rd.\nIt's function is list file.\nIt's an internal command.\nVolume in drive K gas no labe.\nVolume Serial Number is 60F0-6C24n\n");break;
case 4:printf("Command name is cls.\nIt's function is list file.\nIt's an internal command.\nVolume in drive K gas no labe.\nVolume Serial Number is 60F0-6C24n\n");break;
case 5:printf("Command name is date.\nIt's function is list file.\nIt's an internal command.\nVolume in drive K gas no labe.\nVolume Serial Number is 60F0-6C24n\n");break;
case 6:printf("Command name is time.\nIt's function is list file.\nIt's an internal command.\nVolume in drive K gas no labe.\nVolume Serial Number is 60F0-6C24n\n");break;
case 7:printf("Command name is ren.\nIt's function is list file.\nIt's an internal command.\nVolume in drive K gas no labe.\nVolume Serial Number is 60F0-6C24n\n");break;
case 8:printf("Command name is copy.\nIt's function is list file.\nIt's an internal command.\nVolume in drive K gas no labe.\nVolume Serial Number is 60F0-6C24n\n");break;
case 9:printf("dir\tcd\tmd\tcls\ndate\ttime\tren\tcopy\nEnter\"quite\"to quit this program!!\n");break;
case 10:printf("Thanks for using it ,bye!!\n");break;
return 1;
}
printf("No this one!!\nNot a internal commal.\n");
return 0;
}
感想:c语言虽然之前学过,可是都忘得七七八八了,虽然代码大多数为参考网络的,但也有理解了。通过这次的实验,认识到了代码编程不仅仅只是懂了就好,还得多多练习。