Programming of command interpreter

Source: Internet
Author: User
Tags clear screen strcmp

First, the purpose of the experiment

(1) Master the Principle of command interpretation procedure;

(2) Master the simple Dos call method;

(3) 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.

Test methods, steps and Results

1. SOURCE program Name: The source program name MiniOS.cpp in the archive package file

Executable Program Name: MiniOS.exe

2. Principle Analysis and flowchart

#include <stdio.h>
#include <string.h>
void Main ()/* Main function */
{
Char *b[11]={"dir", "CD", "MD", "RD", "CLS", "Date", "Time", "Ren", "Copy", "Help", "quit"}; /* Pointer array store keywords */
int pan (char Ch1[],char *j[11]);
Char a[10],*p=a;
printf ("Welcome.........\npleas Enter a Command!\nenter ' quit ' to quit.\nfor help,enter ' help '. \ n");
c1:printf ("c:\>$");
scanf ("%s", a);
Pan (P,B); /* Function call */
if (strcmp (a,b[10])!=0)/* Compare input string Whether quit end command */
Goto C1;

else printf ("out of work!! \ n ");
}
int pan (char Ch1[],char *j[11])/* Child function */
{
int i;
for (i=0;i<11;i++)
if (strcmp (Ch1,j[i]) ==0)/* compares the input string with the keyword of the array */
{
Switch (i)
{
Case 0:printf ("dir internal command to view files and folders in the current directory \ n");
Case 1:PRINTF ("CD internal command enters a specific directory. \ n ");
Case 2:PRINTF ("MD internal command establishes a specific folder \ n");
Case 3:printf ("Rd internal command deletes a specific folder \ n");
Case 4:printf ("CLS Internal command indicates clear screen function \ n");
Case 5:printf ("date internal command set day \ n");
Case 6:printf ("Time internal command sets or displays system period \ n");
Case 7:printf ("ren internal command means file changed to a name \ n");
Case 8:printf ("Copy internal command copies at least one file to another location \ n");
Case 9:printf ("dir internal command to view files and folders in the current directory \T\NCD internal commands into a specific directory. \T\NMD internal commands to establish specific folders \T\NRD internal commands to delete specific folders \t\ncls internal commands for clear screen function \t\ndate Internal command set Date \t\ntime internal command set or display system period \t\nren internal command means file changed name \ T\ncopy internal command means copy command \nenter \ "Quit\" to quit this program!! \ n ");
Case 10:printf ("Thanks for using it,bye!! \ n ");
}
return 1;}
if (strcmp (Ch1,j[i])!=0)
printf ("Input command error!\n");
return 0;

}

4. Operation Result and analysis

Programming of 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.