0324命令解释程序的编写

#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 ]
");
    printf("版本所有 <c> 2009 Micrcmdoft Corporation。保留所有权利

");
    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	%s
",cmd[i].command,cmd[i].function);
                }
                break;
            }
            
            if((stricmp(str,cmd[i].command)==0)&&(cmd[i].a==1))
            {
                printf(""%s"是内部命令,输入正确
",cmd[i].command);
                printf("该命令的作用是:%s
",cmd[i].function);
                break;
            }
            else if((stricmp(str,cmd[i].command)==0)&&(cmd[i].a==0))
            {
                printf(""%s"是外部命令,输入正确
",cmd[i].command);
                printf("该命令的作用是:%s
",cmd[i].function);
                break;
            }
            else if((stricmp(str,cmd[i].command)!=0)&&(i==n))
            {
                printf("'%s'不是内部或外部命令,也不是可运行的程序或批处理文件
",str);
            }
        }
        printf("
");
    }
}

运行结果:

原文地址:https://www.cnblogs.com/4249ken/p/5316334.html