Programming of a DOS command interpreter

Source: Internet
Author: User
Tags clear screen

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

Select with a while statement and then nest using If,else if. When the command is entered, the command will be interpreted, input the help view command prompt, enter quit program. Use the strcmp comparison function, such as strcmp (Str,cmd[0]) ==0, compared to the previous array, the same is 0, and the difference is 1. 0 o'clock implements the output.

#include <stdio.h>
#include <stdlib.h>
# include<string.h>
Main ()
{
Char cmd[30][30]={"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 ("View current directory \ n");
printf ("\ n");
printf ("\ n");
Break
}
else if (strcmp (str,cmd[1]) ==0)
{
printf ("type: internal command \ n");
printf ("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 ("Create a new directory \ n");
printf ("\ n");
printf ("\ n");
Break
}
else if (strcmp (str,cmd[3]) ==0)
{
printf ("type: internal command \ n");
printf ("Delete this directory ... \ n");
printf ("\ n");
printf ("\ n");
Break
}
else if (strcmp (str,cmd[4]) ==0)
{

printf ("type: internal command \ n");
printf ("Clear screen \ n");

printf ("\ n");
printf ("\ n");
Break
}
else if (strcmp (str,cmd[5]) ==0)
{
printf ("type: internal command \ n");
printf ("Show or set date??? \ n ");
printf ("\ n");
printf ("\ n");
Break
}
else if (strcmp (str,cmd[6]) ==0)
{
printf ("type: internal command \ n");
printf ("Show or set system time \ n");
printf ("\ n");
printf ("\ n");
Break
}
else if (strcmp (str,cmd[7]) ==0)
{
printf ("type: internal command \ n");
printf ("Rename file \ n");
printf ("\ n");
printf ("\ n");
Break
}
else if (strcmp (str,cmd[8]) ==0)
{
printf ("type: internal command \ n");
printf ("Copy at least one file to another location \ n");
printf ("\ n");
printf ("\ n");
Break
}
else if (strcmp (str,cmd[9]) ==0)
{
return 0;

}
}


}
}
}

Programming of a DOS command interpreter

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.