#include<stdio.h> #include<string.h> #include<stdlib.h> #define n 100 typedef struct node{ char name[20]; char use[100]; int pro; int ten; }DOS; int count=0; //读取文件 void ReadField(DOS dos[]) { FILE *fp; if((fp=fopen("cmd.txt","a+"))==NULL) { printf("File open error!\n"); exit(0); } while(!feof(fp)&&fgetc(fp)!=EOF) { fseek(fp,-1L,SEEK_CUR); fscanf(fp,"%s%s%d%d",&dos[count].name,&dos[count].use,&dos[count].pro,&dos[count].ten); count++; } if(fclose(fp)) { printf("Can not close the file!\n"); exit(0); } } //help显示功能 void display(DOS dos[]) { int i; for(i=0;i<count;i++) printf("%s\t%s\n",dos[i].name,dos[i].use); } void Choose(DOS dos[]) { int i; char str[11]; bool flag=false; while(1) { printf("C:\\Documents and Settings\\hskd>"); gets(str); strupr(str); //小写转换成大写 if(strcmp(str,"HELP")==0) { printf("有关某个命令的详细信息,请输入 HELP 命令名\n"); display(dos); flag=true; printf("\n有关工具的详细信息,请参阅联机帮助中的命令行参考。\n\n"); } else if(strcmp(str,"QUIT")==0) exit(0); else if(strcmp(str,"CLS")==0) system("cls"); //引用系统cls功能进行清屏 else { for(i=0;i<12;i++) { if(strcmp(str,dos[i].name)==0) { if(dos[i].pro==1) { if(dos[i].ten==1) printf("‘%s‘ 内部命令输入正确!\n该命令的作用是:%s\n该命令运行需要参数支持\n\n",str,dos[i].use); else printf("‘%s‘ 内部命令输入正确!\n该命令的作用是:%s\n该命令运行并不需要参数支持\n\n",str,dos[i].use); } else { if(dos[i].ten==1) printf("‘%s‘ 外部命令输入正确!\n该命令的作用是:%s\n该命令运行需要参数支持\n\n",str,dos[i].use); else printf("‘%s‘ 外部命令输入正确!\n该命令的作用是:%s\n该命令运行并不需要参数支持\n\n",str,dos[i].use); } flag=true; } } if(!flag) { if(strcmp(str,"quit")!=0) { strlwr(str); //大写转换成小写 printf("‘%s‘ 不是内部或外部命令,也不是可运行的程序\n或批处理文件\n\n",str); } } } } } main() { DOS dos[n]; printf("Microsoft Window XP [版本 5.1.2600]\n"); printf("<C> 版权所有 1985-2001 Microsoft Corp.\n\n"); ReadField(dos); Choose(dos); }
原文:http://www.cnblogs.com/blueYE00/p/5316468.html