Operating system--experiment One

Source: Internet
Author: User

Experiment 1 The programming of the command interpreter one, the experimental purpose

(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

1, the experiment content: According to the teacher designated experiment project, completes the design, the code, the test work.

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.

Test methods, steps and Results

1, the experimental method: using the C language while loop to control the entire command interpreter, the use of the IF and else if statements within the loop, the condition is to use the STRCMP function to filter.

2, the experimental steps: First define two string array, one holds the input display prompt, the other defines the relevant commands in advance DIR, CD, MD, RD, CLS, date, time, Ren, copy and so on. The IF and else if statements are then nested with the while loop statement. When the input command correctly displays the explanation of this command, if the input is an external command, the input error will be re-entered.

3. Source code:

1#include <stdio.h>2#include <string.h>3 Main ()4{//use an array to represent all the commands, starting with 0,5      Charcmd[ -][ -]={"dir","CD","MD","Rd","CLS","Date"," Time","Ren","Copy"," Help","quit"}; 6    7       Charstr[ -]; 8 9  //within a while statement, If,else if, indicates that when a different command is entered, the element of the array is called, the corresponding information is displayed,Ten      //help tips, quit quit the program, One    A       while(1){    -printf"d:/> Please enter a display character:");  -Gets (str);//input from keyboard, display prompt message the    -    -      if(strcmp (str,cmd[0])==0)  -      { +printf"dir indicates no parameters: View files and folders in the current directory \ n");}  -     Else if(strcmp (str,cmd[1])==0)  +      { Aprintf"CD Directory Name: Enter a specific directory. \ n"); at      }   -      Else if(strcmp (str,cmd[2])==0)  -      { -printf"MD Directory Name: Create a specific folder. Dos under the habit called Directory, win under the habit called folder \ n"); -      }  -      Else if(strcmp (str,cmd[3])==0)  in      { -printf"Rd Directory Name: Deletes a specific folder. \ n"); to      }  +      Else if(strcmp (str,cmd[4])==0)     -      { theprintf"CLS Directory Name: Indicates clear screen function \ n"); *     }   $      Else if(strcmp (str,cmd[5])==0) Panax Notoginseng      { -printf"Data Set Date command, function is set date \ n"); the      }   +     Else if(strcmp (str,cmd[6])==0)  A      { theprintf"Time system Clock Settings command, function: Set or display the system period. \ n"); +      }  -      Else if(strcmp (str,cmd[7])==0)   $      {  $printf"Ren means that the file is renamed, and the Ren command is in the format: the file name of the Ren source file. \ n"); -      }  -      Else if(strcmp (str,cmd[8])==0)  the      { -printf"Copy represents the replication command, and his function is to copy the information \ n"); Wuyi      }  the   -      //enter Help to display all internal commands Wu      Else if(strcmp (str,cmd[9])==0)  -      { Aboutprintf"dir No parameters: View files and folders in the current directory \ n");  $printf"CD Directory Name: Enter a specific directory. \ n");  -printf"MD Directory Name: Create a specific folder. Dos under the habit called Directory, win under the habit called folder) \ n");  -printf"Rd Directory Name: Deletes a specific folder. \ n");  -printf"CLS Directory Name: Indicates clear screen function \ n");  Aprintf"Data Set Date command, function is set date \ n");  +printf"Time system Clock Settings command, function: Set or display the system period. \ n");  theprintf"Ren means that the file is renamed, and the Ren command is in the format: the file name of the Ren source file. \ n");  -printf"Copy represents the Replication command, and the replication information for his features \ n"); $      }   the      Else if(strcmp (str,cmd[Ten])==0) the          the         returnprintf"Thank you have quit the command interpreter! "); the       -      Else   in      {     theprintf"you enter the wrong information, please re-enter: \ n");  the      }   About    the      } the}


4. The results of the operation are as follows:
            

Operating system--experiment One

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.