zoukankan      html  css  js  c++  java
  • 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("
    ");
        }
    }

    运行结果:

  • 相关阅读:
    CENTOS7下安装REDIS
    Linux 查看端口状态netstat
    Centos7启动zookeeper无法连接2181端口
    企业信息化之路---集成
    Linux启动/停止/重启Mysql数据库的方法
    详解线程池
    详细的RocketMQ说明
    2021面试题准备~~~
    Https原理详解
    es 常用DSL
  • 原文地址:https://www.cnblogs.com/4249ken/p/5316334.html
Copyright © 2011-2022 走看看