I. Purpose and Requirements
1. 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.
2 . Experimental requirements
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.
Ii. contents of the experiment
According to the requirements, complete the design, coding, testing work.
three
, experimental environment
1. PC Microcomputer
2. Windows Operating System
3. A/C + + program Development Integration Environment
Four, the experiment
principle and core algorithm reference program segment
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
Main () {
Char cmd[20][20]={"dir", "CD", "MD", "RD", "CLS", "Date", "Time", "Ren", "Copy", "Quit", "help"};
Char str[10];
int i;
while (1) {
printf (" Please enter the prompt :>");
Gets (str);
for (i=0;i<20;i++) {
{
if (strcmp (str,cmd[0]) ==0) {
printf (" Type: internal command \ n");
printf (" function: View current directory \ n");
printf ("\ n");
printf ("\ n");
Break
}
else if (strcmp (str,cmd[1]) ==0) {
printf (" Type: internal command \ n");
printf (" function: Show the name of the current directory \ n");
printf ("\ n");
printf ("\ n");
Break
}
else if (strcmp (str,cmd[2]) ==0) {
printf (" Type: internal command \ n");
printf (" function: Create a new directory \ n");
printf ("\ n");
printf ("\ n");
Break
}
else if (strcmp (str,cmd[3]) ==0) {
printf (" Type: internal command \ n");
printf (" function: Delete this directory \ n");
printf ("\ n");
printf ("\ n");
Break
}
else if (strcmp (str,cmd[4]) ==0) {
printf (" Type: internal command \ n");
printf (" function: Clear screen \ n");
printf ("\ n");
printf ("\ n");
Break
}
else if (strcmp (str,cmd[5]) ==0) {
printf (" Type: internal command \ n");
printf (" function: Display or set date \ n");
printf ("\ n");
printf ("\ n");
Break
}
else if (strcmp (str,cmd[6]) ==0) {
printf (" Type: internal command \ n");
printf (" function: Show or set system time \ n");
printf ("\ n");
printf ("\ n");
Break
}
else if (strcmp (str,cmd[7]) ==0) {
printf (" Type: internal command \ n");
printf (" function: Rename file \ n");
printf ("\ n");
printf ("\ n");
Break
}
else if (strcmp (str,cmd[8]) ==0) {
printf (" Type: internal command \ n");
printf (" function: Copy at least one file to another location \ n");
printf ("\ n");
printf ("\ n");
Break
}
else if (strcmp (str,cmd[9]) ==0) {
return 0;
}
else if (strcmp (str,cmd[10]) ==0) {
printf (" type: external command \ n");
printf (The dir\t internal command displays the files and subdirectories in a directory. \ n ");
printf (The Cd\t internal command displays the name of the current directory or changes it. \ n ");
printf ("Md\t internal command creates a directory. \ n ");
printf ("rd\t internal command deletes the directory. . \ n ");
printf ("cls\t internal command clears the screen. \ n ");
printf ("Date\t internal command displays or sets the date. \ n ");
printf ("Time\t internal Command Internal command displays or sets the system time.") \ n ");
printf ("ren\t internal command renames the file. \ n ");
printf (The Cope\t Internal command copies at least one file to another location. \ n ");
printf (the help\t External command provides Help for Windows commands. \ n ");
printf ("quit\t external command to exit command interpreter \ n");
printf ("\ n");
printf ("\ n");
/* printf ("call\t" calls this one from a batch program.) \ n ");
printf ("Cmd\t" opens another Windows Command Interpretation window.) \ n ");
printf ("color\t" sets the default console foreground and background color.) \ n ");
printf ("del\t" deletes at least one file. \ n ");
printf ("exit\t exit command interpreter.") \ n ");
printf ("Find\t searches one or more files for a text string. \ n ");
printf ("mkdir\t" creates a directory. \ n ");
printf ("mode\t" configures the system device. \ n ");
printf ("print\t prints a text file. \ n ");
printf ("replace\t" replaces the file. \ n ");
printf ("Rename\t" renames the file. \ n "); * /
Break }
else if (strcmp (Str,cmd[i])!=0) {
printf (" This command is not an internal or external command, nor is it a running program or batch file !\n");
printf ("\ n");
Break
}
}
}
}
}
Experiment 1 The programming of DOS command interpreter