Experiment one report
Experiment one, the programming of DOS command interpreter
13 Internet of Things engineering Zhang Xuiling 201306104140
First, the purpose of the experiment
(1) Recognize DOS;
(2) Master the Principle of command interpretation procedure;
(3) Master the Simple Dos call method;
(4) Master C language programming preliminary.
Second, the contents and requirements of the experiment
Write a command-line interpreter similar to Dos,unix
(1) Self-defined system prompt
(2) Custom set of commands (8-10)
(3) User input Help to find commands
(4) List the function of the command, distinguish internal or external commands
(5) User input quit quit
(6) Internal commands are dir, CD, Md,rd, CLS, date, time, Ren, copy, etc.
According to the requirements, complete the design, coding, testing work.
Test methods, steps and Results
- SOURCE program Name: ZXL.C
Executable Program Name: Zxl.exe
2. Principle Analysis and Procedure
Principle Analysis: Define a one- dimensional array and a two-dimensional array, an array to hold the user input command, two-dimensional array to hold various internal commands , when the user input each command, are displayed with the corresponding prompts.
Step: First, define an array to hold the user input command, two-dimensional array to hold various internal commands, and then, using the STRCMP function to determine whether the user input string is equal to the string in the array, if equal, the output of the hint in printf, if not equal, prompt error.
3. Main procedural paragraphs and their explanations
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main ()
{
Char cmd[30][30]={"dir", "CD", "MD", "RD", "CLS", "Date", "Time", "Ren", "Copy", "Help", "quit"};//defines a two-dimensional array, storing various internal commands
Char str[20]={0};//defines a one-dimensional array for storing user input commands
while (1)
{
printf ("Welcome to Dos!\nplease Enter the command:");
scanf ("%s", &STR);
if (strcmp (str,cmd[0]) ==0)//strcmp function is used to determine if the strings are equal
{
printf ("Dir can view files in the current directory \ n");
}
else if (strcmp (str,cmd[1]) ==0)
{
printf ("CD can enter a specific directory \ n");
}
else if (strcmp (str,cmd[2]) ==0)
{
printf ("MD can create a custom folder \ n");
}
else if (strcmp (str,cmd[3]) ==0)
{
printf ("Rd can delete a specific folder \ n");
}
else if (strcmp (str,cmd[4]) ==0)
{
printf ("CLS has clear screen function \ n");
}
else if (strcmp (str,cmd[5]) ==0)
{
printf ("Date can be set to day \ n");
}
else if (strcmp (str,cmd[6]) ==0)
{
printf ("Time can set or display the system clock \ n");
}
else if (strcmp (str,cmd[7]) ==0)
{
printf ("Ren can change file name \ n");
}
else if (strcmp (str,cmd[8]) ==0)
{
printf ("Copy can copy information \ n");
}
else if (strcmp (str,cmd[9]) ==0)
{
printf ("Dir can view files in the current directory \ n");
printf ("CD can enter a specific directory \ n");
printf ("MD can create a custom folder \ n");
printf ("Rd can delete a specific folder \ n");
printf ("CLS has clear screen function \ n");
printf ("Date can be set to day \ n");
printf ("Time can set or display the system clock \ n");
printf ("Ren can change file name \ n");
printf ("Copy can copy information \ n");
}
else if (strcmp (str,cmd[10]) ==0)
{
return 0;
}
Else
{
printf ("You enter the wrong information, please re-enter: \ n");
}
}
return 0;
}
4. Operation Results and Analysis
Start Page and help :
dir command:
CD command:
Date command:
Time command:
Iv. Summary of the experiment
It is not difficult to write a DOS command interpreter, but it takes some time to do it. Defines an array that holds commands and uses the STRCMP function to determine whether strings are equal. In the process of running the error, is a two-dimensional array of numbers set too small to cause problems, after modification, there is no error. This clearly shows the overall structure of the program, using If,else if and else to enumerate the different meanings represented by each character.
1006 Experimental One experimental report