Experiment one, the programming of DOS command interpreter

Source: Internet
Author: User
Tags strcmp

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.

Third, the experimental environment

1. PC Microcomputer

2. Windows Operating System

3. A/C + + program Development Integration Environment
Four experimental code
#include <stdio.h>
#include <string.h>
Main ()
{
Char cmd[20][20]={"dir", "CD", "MD", "RD", "CLS", "Date", "Time", "Ren", "Copy", "Help", "quit"};
Char str[20];
while (1)
{
printf ("Please enter the indicator");
Gets (str);//gets reads the string function from the standard input device. Can be read indefinitely without judging the upper limit to enter the end of the read
if (strcmp (str,cmd[0]) ==0)
{
printf ("dir means no parameters: View the text and folder of the current directory \ n");
}
else if (strcmp (str,cmd[1]) ==0)
{
printf ("CD directory name: Enter a specific directory \ n");
}
else if (strcmp (str,cmd[2]) ==0)
{
printf ("MD Directory name: Create a specific folder \ n");
}
else if (strcmp (str,cmd[3]) ==0)
{
printf ("Rd Directory name: delete a specific folder \ n");
}
else if (strcmp (str,cmd[4]) ==0)
{
printf ("CLS clears screen \ n");
}
else if (strcmp (str,cmd[5]) ==0)
{
printf ("Data set date command \ n");
}
else if (strcmp (str,cmd[6]) ==0)
{
printf ("Time system clock set command \ n");
}
else if (strcmp (str,cmd[7]) ==0)
{
printf ("Ren means file changed to name \ n");
}
else if (strcmp (str,cmd[8]) ==0)
{
printf ("copy indicates copy command \ n");
}
else if (strcmp (str,cmd[9]) ==0)
{

printf ("dir means no parameters: View the text and folder of the current directory \ n");
printf ("CD directory name: Enter a specific directory \ n");
printf ("MD Directory name: Create a specific folder \ n");
printf ("Rd Directory name: delete a specific folder \ n");
printf ("CLS clears screen \ n");
printf ("Data set date command \ n");
printf ("Time system clock set command \ n");
printf ("Ren means file changed to name \ n");
printf ("copy indicates copy command \ n");


}
else if (strcmp (str,cmd[10]) ==0)
Return
Else
{
printf ("You enter the wrong information, please re-enter: \ n");
}
}

}

Five experimental results and

Start interface for running the program

Enter Help to display all command characters and features

Enter the wrong character and prompt the user to re-enter

Example

Enter quit to exit the loop

Six Summary and experience

This experiment uses the C language to program, but for a freshman learned knowledge has forgotten, on the internet and in the book to find relevant information,

Finally complete the program.

Experiment one, the programming of 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.