vim中的拷贝和粘贴:v 可视化选择;y拷贝,p粘贴
先按一个v,然后按上下左右键的右键,按y 就拷贝完成
到合适的位置粘贴
课程第八节
要求写一个可以实现命令行的小程序
自己实现:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
void dothis(char * cmd)
{
printf("this is %s",cmd);
if(strcmp(cmd,"help")==0)
{
printf("haha");
}
else if(strcmp(cmd,"help")==0)
{
printf("sisi");
}
}
int main()
{
char cmd[1024];
while(1)
{
scanf("%s",cmd);
if(strcasecmp(cmd,"null")!=0)
{
dothis(cmd);
}
}
return 0;
}
课上老师实现:
/********************************************************************/
/*Copyright (C) mc2lab.com,SSE@USTC,2014-2015 */
/* */
/*File NAME :menu.c */
/*PRINCIPAL AUTHOR :Mengning */
/*SUBSYSTEM NAME :menu */
/*MODULE NAME :menu */
/*LANGUAGE :C */
/*TARGET ENVIRONMENT :ANY */
/*DATE OF FIRST RELEASE :2014/08/31 */
/*DESCRIPTION :This is a menu program */
/********************************************************************/
/*
* Revision log:
*
* Created by Mengning,2014/08/31
*
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int Help();
#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 中加入,变为
static tDataNode head[]=
{
{"help","this is help cmd!",Help,&head[1]},
{"version","menu program v1.0",NULL,&head[2]}
{"quit","this is help quit!",Quit,NULL},
};
再加入Quit()函数
*/
static tDataNode head[]=
{
{"help","this is help cmd!",Help,&head[1]},
{"version","menu program v1.0",NULL,NULL}
};
int main()
{
/*cmd line begins */
while(1)
{
char cmd[CMD_MAX_LEN];
printf("Input a cmd number>");
scanf("%s",cmd);
tDataNode *p=head;
// printf("this is head data :%s",head->cmd);
while(p!=NULL)
{
if(0==strcmp(p->cmd,cmd))
{
printf("%s-%s\n",p->cmd,p->desc);
if(p->handler!=NULL)
{
p->handler();
}
p=p->next;
}
if(p==NULL)
{
printf("This is a wrong cmd!\n");
}
}
}
return 0;
}
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;
}