内部模块化的命令行菜单
来源:互联网 发布:数控机床加工仿真软件 编辑:程序博客网 时间:2024/05/17 22:00
win7与VMware ubuntu虚拟机的共享文件夹在cd /mnt/hgfs下
linklist.h:
/**************************************************************************************************//* Copyright (C) LS, 2014-2015 *//* FILE NAME : linklist.h *//* PRINCIPAL AUTHOR : ls *//* SUBSYSTEM NAME : menu *//* MODULE NAME : linklist *//* LANGUAGE : C *//* TAGRGET ENVIRONMENT : ANY *//* DATE OF FIRST RELEASE : 2014/12/21 *//* DESCRIPTION : linklist for menu progrom *//**************************************************************************************************//* * Revision log: * * Created by ls, 2014/12/21 * *//* data struct and its operations */typedef struct DataNode{ char* cmd; char* desc; int (*handler)(); struct DataNode *next;} tDataNode;/* find a cmd in the linklist and return the data node pointer */tDataNode * FindCmd(tDataNode *head, char *cmd);/* show all cmd in linklist */int ShowAllCmd(tDataNode* head);
/**************************************************************************************************//* Copyright (C) LS, 2014-2015 *//* FILE NAME : linklist.c *//* PRINCIPAL AUTHOR : LISUN *//* SUBSYSTEM NAME : menu *//* MODULE NAME : linklist *//* LANGUAGE : C *//* TAGRGET ENVIRONMENT : ANY *//* DATE OF FIRST RELEASE : 2014/12/21 *//* DESCRIPTION : linklist for the menu progrom *//**************************************************************************************************//* * Revision log: * * Created by ls, 2014/12/21 * */#include <stdio.h>#include <stdlib.h>#include "linklist.h"tDataNode* FindCmd(tDataNode* head, char* cmd){ if (head == NULL || cmd == NULL) { return NULL; } tDataNode *p = head; while (p != NULL) { if (strcmp(p->cmd, cmd) == 0) { return p; } p = p->next; } return NULL;} int ShowAllCmd(tDataNode* head){ printf("Menu List:\n"); tDataNode *p = head; while (p != NULL) { printf("%s - %s\n", p->cmd, p->desc); p = p->next; } return 0;}
menu.c
/**************************************************************************************************//* Copyright (C) LS, 2014-2015 *//* FILE NAME : menu.c *//* PRINCIPAL AUTHOR : LISUN *//* SUBSYSTEM NAME : menu *//* MODULE NAME : menu *//* LANGUAGE : C *//* TAGRGET ENVIRONMENT : ANY *//* DATE OF FIRST RELEASE : 2014/12/21 *//* DESCRIPTION : This is a menu progrom *//**************************************************************************************************//* * Revision log: * * Created by ls, 2014/12/21 * */#include <stdio.h>#include <stdlib.h>#include "linklist.h"int Help();int Quit();#define CMD_MAX_LEN 128#define DESC_LEN 1024#define CMD_NUM 10/*typedef struct DataNode{ char* cmd; char* desc; int (*handler)(); struct DataNode *next;} tDataNode;tDataNode* FindCmd(tDataNode* head, char* cmd){ if (head == NULL || cmd == NULL) { return NULL; } tDataNode *p = head; while (p != NULL) { if (strcmp(p->cmd, cmd) == 0) { return p; } p = p->next; } return NULL;} int ShowAllCmd(tDataNode* head){ printf("Menu List:\n"); tDataNode *p = head; while (p != NULL) { printf("%s - %s\n", p->cmd, p->desc); p = p->next; } return 0;}*/static tDataNode head[] ={ {"help", "this is help cmd!", Help, &head[1]}, {"version", "menu program v1.0", NULL, &head[2]}, {"quit", "Quit from menu", Quit, NULL}};int main (){ /* cmd line begins */ while (1) { char cmd[CMD_MAX_LEN]; printf("Input a cmd number > "); scanf("%s", cmd); tDataNode *p = FindCmd(head, cmd); if (p == NULL) { printf("This is a wrong cmd!\n"); continue; } printf("%s - %s\n", p->cmd, p->desc); if (p->handler != NULL) { p->handler(); } }}int Help(){ printf("Menu List:\n"); tDataNode *p = head; while (p != NULL) { printf("%s - %s\n", p->cmd, p->desc); p = p->next; } return 0;}int Quit(){ exit(0);}
参考:
【1】 win7与VMware ubuntu虚拟机实现文件共享(最后一定要装open-vm-dkms插件)http://blog.csdn.net/warringah1/article/details/8927437
0 0
- 内部模块化的命令行菜单
- 内部模块化的命令行菜单小程序
- 内部模块化的命令行菜单小程序
- 实验报告三:内部模块化的命令行菜单小程序V2.0
- 实验三:内部模块化的命令行菜单小程序V2.0
- 实验三:内部模块化的命令行菜单小程序V2.0
- 文章标题 实验三:内部模块化的命令行菜单小程序V2.0
- [高级软件工程实验]内部模块化的命令行菜单小程序V2.0
- 实验三:内部模块化的命令行菜单小程序V2.0
- 实验三:内部模块化的命令行菜单小程序V2.0
- 软件工程(C编码实践篇) 实验三:内部模块化的命令行菜单
- 学习之路——内部模块化的命令行菜单 V1.1
- 实验三:内部模块化的命令行菜单小程序V2.0
- 实验三:内部模块化的命令行菜单小程序V2.0
- 实验报告三:内部模块化的命令行菜单小程序V2.0
- 实验三:内部模块化的命令行菜单小程序V2.0
- 实验三:内部模块化的命令行菜单小程序V2.0
- “软件工程(C编码实践篇)”实验报告【实验三:内部模块化的命令行菜单小程序V2.0】
- 同步与异步详解
- Hibernate对查询结果的简单处理
- sqlplus 上下键
- 第十七周 项目6.1 求出每名同学的总分和均分
- 流程控制
- 内部模块化的命令行菜单
- 搬家
- Could not determine type for: String
- samba配置实战
- CronTab命令实例
- jbpm学习七
- 您需要Administrators提供的权限才能对此文件进行更改
- 信息发布,不错的选择
- 接着写被sina吃了的博文