标签:
#include<stdio.h> #include<conio.h> #include<string.h> #include<stdlib.h> #define N 200 struct minicmd { int a; char command[50]; char function[100]; }; struct minicmd cmd[N]; main() { FILE *fp; int i,n; char str[N]; printf("Micrcmdoft Windows [版本 6.1.7601 ]\n"); printf("版本所有 <c> 2009 Micrcmdoft Corporation。保留所有权利\n\n"); fp=fopen("cmd.txt","r+"); for(i=0;!feof(fp);i++) { fscanf(fp,"%s%s%d",cmd[i].command,cmd[i].function,&cmd[i].a); n=i; } fclose(fp); while(1){ printf("C:\\Users\\Administrator.USER-20151120JI>"); gets(str); for(i=0;i<=n;i++) { if(stricmp(str,"help")==0) { for(i=0;i<=n;i++) { printf("%s\t%s\n",cmd[i].command,cmd[i].function); } break; } if((stricmp(str,cmd[i].command)==0)&&(cmd[i].a==1)) { printf("\"%s\"是内部命令,输入正确\n",cmd[i].command); printf("该命令的作用是:%s\n",cmd[i].function); break; } else if((stricmp(str,cmd[i].command)==0)&&(cmd[i].a==0)) { printf("\"%s\"是外部命令,输入正确\n",cmd[i].command); printf("该命令的作用是:%s\n",cmd[i].function); break; } else if((stricmp(str,cmd[i].command)!=0)&&(i==n)) { printf("‘%s‘不是内部或外部命令,也不是可运行的程序或批处理文件\n",str); } } printf("\n"); } }
运行结果:
标签:
原文地址:http://www.cnblogs.com/4249ken/p/5316334.html