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

来源:互联网 发布:刷机精灵mac版 编辑:程序博客网 时间:2024/06/05 08:01

版本库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】

原创粉丝点击