[高级软件工程实验]命令行菜单小程序V1.0

版本库URL:https://github.com/swagnhen/Advanced-Software-Engineering-Exercise.git

实验过程

1.命令行菜单小程序

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>

int main()
{
    char cmd[128];
    printf("**********Shelllet Running**********\n");
    while (1)
    {
        printf(">>>");
        scanf("%s", cmd);
        if (strcmp(cmd, "hello") == 0)
        {
            printf(">>>Welcome to shelllet!\n");
        }
        else if (strcmp(cmd, "showUid") == 0)
        {
            printf(">>>UID: %i\n", getuid());
        }
        else if (strcmp(cmd, "man") == 0)
        {
            printf(">>>This is \"man\" commend\n");
        }
        else if (strcmp(cmd, "cd") == 0)
        {
            printf(">>>This is \"cd\" commend\n");
        }
        else if (strcmp(cmd, "ls") == 0)
        {
            printf(">>>This is \"ls\" commend\n");
        }
        else if (strcmp(cmd, "ipconfig") == 0)
        {
            printf(">>>This is \"ipconfig\" commend\n");
        }
        else if (strcmp(cmd, "env") == 0)
        {
            printf(">>>This is \"env\" commend\n");
        }
        else if (strcmp(cmd, "quit") == 0)
        {
            printf("**********Shelllet End**********\n");
            exit(0);
        }
        else
        {
            printf(">>>Wrong Commend\n");
        }
    }
    return 0;
}

运行效果
这里写图片描述

实验总结与问题

一开始我还以为是要像操作系统序章那样, 利用fork()和execve()实现一个简单的shell
本来想着解析指令字符串还是很复杂的有点头痛
后来看到老师视频中演示的help指令的实现, 就没有这个烦恼了, 放弃了治疗

【Swegnhan + 《软件工程(C编码实践篇)》MOOC课程作业http://mooc.study.163.com/course/USTC-1000002006

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值