您的位置:首页 > 理论基础 > 计算机网络

软件工程网络课程作业二:命令行菜单小程序

2017-09-18 16:19 375 查看
【clksjx + 《软件工程(C编码实践篇)》MOOC课程作业http://mooc.study.163.com/course/USTC-1000002006

实验代码

#include<stdio.h>
#include<string.h>  //for the strcmp()
#include<stdlib.h>  //for the exit()

void helpCommand()
{
printf("Help menu:\n");
printf(" 1.function helps\n");
printf(" 2.config helps\n");
printf(" ...\n");
printf(" Please enter a number representing your choice.\n");

}

void functionHelps()
{
printf("This command is for the function helps.");
}

void configHelps()
{
printf("This command is for the config helps.");
}

void helloCommand()
{
printf("Hello there! This command is just for testing.\n");
}

void exitCommand()
{
exit(0);
}

void errorCommand()
{
printf("Please input a valid command!");
}

int main()
{
char cmd[128];
while(1)
{
scanf("%s", cmd);
if(strcmp(cmd, "help") == 0)
{
helpCommand();
}
else if(strcmp(cmd, "hello") == 0)
{
helloCommand();
}
else if(strcmp(cmd, "exit") == 0)
{
exitCommand();
}
else if(strcmp(cmd, "1") == 0)
{
functionHelps();
}
else if(strcmp(cmd,"2") == 0)
{

8865
configHelps();
}
else
{
errorCommand();
}
}
return 0;
}


实验结果



遇到的问题及解决方法

vi不显示当前的模式状态。因为ubuntu默认安装的vi是不完整的,可以在命令行模式下输入
set showmode
来设置显示当前模式。

由于在windows下习惯
Ctrl+s
进行保存, 导致系统没有反应。因为在Linux中
Ctrl+s
是暂停系统的快捷键,可以通过按
Ctrl+q
恢复虚拟机工作状态。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: