实验一 操作系统

  1 #include<stdio.h>
  2 #include<stdlib.h>
  3 #include <string.h>
  4 char *rword[]={"dir","cd","md","rd","cls","date","time","ren","copy","exit","end"};
  5 char ci;
  6 typedef struct{
  7 int num;
  8 char *word;
  9 }WORD; //存储种别码,单词
 10 
 11 typedef struct{
 12 int number;
 13 char means[5000];
 14 }Base; //存储种别码,单词
 15 
 16 int ainput,toke; char input[300];char token[300]=" ";
 17 Base mean[10];
 18 
 19 char mgetch(){ //读取一个字符
 20 ci=input[ainput]; 
 21 ainput=ainput+1;
 22 return (ci);
 23 }
 24 
 25 void getbc(){ //去空格
 26 while(ci==' '||ci==10)
 27 { ci=input[ainput];
 28 ainput+=1;
 29 
 30 }
 31 }
 32 int letter() //判断是否为字母
 33 { if(ci>='a'&&ci<='z'||ci>='A'&&ci<='Z')
 34 return 1;
 35 else 
 36 return 0;
 37 }
 38 int number() //判断是否为数字
 39 { 
 40 if(ci>='0'&&ci<='9')
 41 return 1;
 42 else 
 43 return 0;
 44 } 
 45 int reserve() // 判断是否为关键字
 46 { 
 47 int i=0;
 48 while(strcmp(rword[i],"end"))
 49 { 
 50    if(!strcmp(rword[i],token))
 51    {
 52      return i+1;
 53    }
 54        i++;
 55 }
 56 
 57 return 1001;
 58 
 59 }
 60 
 61 void link() //链接单词
 62 { 
 63 token[toke]=ci;
 64 toke+=1;
 65 token[toke]='';
 66 
 67 }
 68 void back(){
 69 
 70 ainput-=1;
 71 }
 72 
 73 
 74 WORD * scaner(){                //判断字符串
 75 WORD *myword;
 76 myword=(WORD*)malloc(sizeof(WORD));
 77 myword->num=10;
 78 myword->word="";
 79 toke=0;
 80 mgetch();
 81 getbc();
 82 if(letter()){
 83 while(letter()||number())
 84 {
 85 link();
 86 mgetch();
 87 }
 88 back();
 89 myword->num =reserve();
 90 myword->word=token;
 91 return(myword);
 92 }
 93 else switch(ci){
 94 case'': myword->num=1000;
 95 myword->word="over";
 96 return(myword);
 97 break;
 98 
 99 default: 
100 myword->num=-1;
101 myword->word="error";
102 return(myword);
103 
104 }
105 
106 }
107 
108 
109 void saveBase(){         //存储信息
110 int i=0; 
111  
112     for(i=0;i<10;i++)
113     {
114         mean[i].number =i+1;
115     }
116 strcpy(mean[0].means , "主要用来显示一个目录下的文件和子目录。");
117 strcpy(mean[1].means , "改变或显示当前目录");
118 strcpy(mean[2].means , "创建一个子目录 ");
119 strcpy(mean[3].means , " 删除空子目录 ");
120 strcpy(mean[4].means , "清除显示器屏幕上的内容,使DOS提示符到屏幕左上角 ");
121 strcpy(mean[5].means , "显示和设置DOS的系统日期 ");
122 strcpy(mean[6].means , "显示和设置DOS的系统时间 ");
123 strcpy(mean[7].means , "对指定磁盘、目录中的一个文件或一组文件更改名称 ");
124 strcpy(mean[8].means , "在英文中是复制的意思");
125 strcpy(mean[9].means , "退出");
126 
127 }
128 
129 
130 /*void read()
131 {
132 FILE * fp; int i;
133 char data[500]; //char str;
134 if((fp=fopen("G:\datafile.txt","r"))==NULL)
135 {
136    printf("file cannot be opened
");
137    
138    }
139           i=0;
140    while(!feof(fp))                      
141    {     
142       data[i++]=fgetc(fp);
143            i++;
144       data[i]='';  
145            i--;                                              
146       if(i>=500)                                       
147        {
148         printf("buffer not enough!");
149         
150         }
151 
152       }
153                                                           
154            printf("%s",data);                             
155            printf("
");  
156        
157    fclose(fp);
158 }
159 */
160 int main()          //主函数
161 { 
162 int over=1; WORD * oneword; int i; char check[10]=""; int j;
163 saveBase();
164 printf("Microsoft Windows [版本 6.3.9600]
");
165 printf("<c> 2013 Microsoft Corporation。保留所有权利
");
166 qq:printf("
C:userlenvon>");
167 i=0;ainput=0;oneword=(WORD*)malloc(sizeof(WORD));
168 do{
169 ci=getchar();
170 input[i]=ci;
171 i++;
172 }while(ci!='
');
173 while(over!=10)
174 {
175 oneword=scaner();
176    if(oneword->num<1000)
177    {
178 //printf("(%d,%s)
",oneword->num,oneword->word);
179      for(j=0;j<10;j++)
180      {
181         if(oneword->num==mean[j].number )
182         {
183         printf("
 %s",mean[j].means );
184            break;
185         }
186      }
187    }
188 else if(oneword->num=1001)
189 printf("不存在所输入的功能");
190 over=oneword->num;
191    if(over!=10)
192    {
193      goto qq;
194    }
195 }
196 }

原文地址:https://www.cnblogs.com/zlcan/p/5316100.html