1009 Experiment One knows DOS

Source: Internet
Author: User

Experiment One, DOS experiment

Internet of things engineering Zhang Yi 201306104149

First, Experimental Purpose

(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, experimental content and 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.

Third, test methods, procedures and results

1. source program Name: Compressed package file (RAR or Zip) source program name 1.c

Executable Program Name: 1.exe

2. principle Analysis and Flowchart

This program is mainly used for nested use of the while (1) statement and if () else () statement, in addition to the use of arrays. Put the desired implementation of the command into the array cmd[20][20], and then put the input string into the array str[20], the two array of strings in the match, if "strcmp (Str,cmd[n]) ==0", the output number n corresponds to the command and its interpretation, if not satisfied " strcmp (Str,cmd[n]) ==0 ", you are prompted to enter an error, re-enter:" Until the input string corresponds to the string in the array cmd[20][20], at which point the output n corresponds to the command. If you do not enter "quit" All the time, you will be prompted to "ask the user to enter a command:" Whenever the statement corresponding to the last command entered is displayed.

3. Main procedural paragraphs and their explanations:

#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];//array that stores strings

printf ("Welcome to the DOS command interpreter!\n\n");

while (1)


printf ("\ n please user input command:");

Gets (str); str equals the input string

if (strcmp (str,cmd[0]) ==0)

comparison function, compared to the previous array, the same as 0 differs from 1 to 0 o'clock output


printf ("dir shows disk directory \ n");


else if (strcmp (str,cmd[1]) ==0)


printf ("CD into a specific directory \ n");


else if (strcmp (str,cmd[2]) ==0)


printf ("MD creates a new directory \ n");//dos the following habits called Directory, win under the habit called folder.


else if (strcmp (str,cmd[3]) ==0)


printf ("Rd Delete folder \ n");


else if (strcmp (str,cmd[4]) ==0)


printf ("CLS clear screen \ n");


else if (strcmp (str,cmd[5]) ==0)


printf ("date dates set \ n");


else if (strcmp (str,cmd[6]) ==0)


printf ("Time set (or display) system period \ n");


else if (strcmp (str,cmd[7]) ==0)


printf ("ren file renamed \ n"); The format of the//ren command is: ren source filename destination file name


else if (strcmp (str,cmd[8]) ==0)


printf ("Copy copy \ n");


else if (strcmp (str,cmd[9]) ==0)//Enter Help to display the following


printf ("dir (no parameter) displays disk directory \ n");

printf ("CD into a specific directory \ n");

printf ("MD creates a new directory \ n");

printf ("Rd Delete specific folder \ n");

printf ("CLS clear screen command \ n");

printf ("date set day \ n");

printf ("Time set or display system period \ n");

printf ("ren file rename command \ n");

printf ("Copy file copying command \ n");

printf ("Quit Quit \ n");


else if (strcmp (str,cmd[10]) ==0)


printf ("Quit Quit \ n");


else//differs from string in array to 1, prompting an error


printf ("Input error, please re-enter: \ n");




4. operation results and Analysis

Run the program with the following effect: "Welcome to the DOS command interpreter!" "and prompts the user to enter a command." Here, the statement "Ask the user to enter a command" is placed inside the while (1) to keep it prompt.

Enter a command that is not set in the registered array of the program, and then prompt for "input error, please reenter:". The If () () () () statement is used here, if "str,cmd[n. ==0" is met, the command corresponding to the number n is displayed and its interpretation is indicated, otherwise "input error, please reenter:".

Enter "Help" to display the commands that are set within the hosted array and their explanations.

Enter the command set within the hosting array, and the command and its interpretation are displayed.

Enter "Quit" to display "quit Quit" and press any key to exit the program.

Iv. Summary of the experiment

This is the first experiment of the operating system, did not know the DOS command, so the internet looked up the relevant information. DOS internal commands are dir, CD, Md,rd, CLS, date, time, Ren, copy, etc., which are briefly explained by the program. After the program runs, it prompts "Welcome to the DOS command interpreter!" and "Ask the user to enter a command", if you do not know the words can enter "help" command, then display DOS commands and related explanations.

When I first started doing experiments, there was only a vague framework concept that I knew could be programmed with the if (), else if () and else () statements, but the idea was messy and I didn't know how to implement it. By finding the relevant books and surfing the program code, we find that the array can solve the problem well. Then use an array to store the command you want to use, and an array to store the command you just entered (string), and then compare it with the previous array, the same as 0 differs from 1, the output is 0 o'clock, and 1 indicates an error, asking for the command to be re-entered. When you enter the "quit" command, Prompt "quit Quit" and exit the input, at which point you can press any key to exit the display.

1009 Experiment One knows DOS

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.