欢迎使用CSDN-markdown编辑器

来源:互联网 发布:私人做网络小贷平台 编辑:程序博客网 时间:2024/06/03 04:42

豆子123第二次作业

Author: 张佳伟 SA17225491

实验目的:通过写一个小的命令行工具,从而形成良好的代吗风格及养成良好的代码规范

第一步:在github上创建一个名叫se_lab2的仓库

第二步:将此版本库clone到本地

git clone http://github.com/zjw121461745/se_lab2.gitcd se_lab2vi cmd.c

然后对此cmd.c文件进行编辑如下:

/****************************************** *       Author:Zhang Jiawei              * *       Date:2017/09/23                  * *       Version:1.0.0                    * *                                        * *                                        * ******************************************/#include <stdio.h>#include <stdlib.h>#include <string.h>#include <time.h>int main(){    char cmd[128];    while(1)    {            printf("******this system have lots of cdm:******\n");        printf("hello*dance*happy*sleep*time*name*teacher*hungry*exit\n");        /*printf("please input a cmd");        printf("please input a cmd");        printf("please input a cmd");*/        printf("please input a cmd~~~\n");        scanf("%s", cmd);        if(!strcmp(cmd, "exit"))        {            exit(0);        }        else if(!strcmp(cmd, "hello"))        {            printf("hello, zjw~\n");        }        else if(!strcmp(cmd, "sleep"))        {            printf("this is the 'sleep' cmd\n");        }        else if(!strcmp(cmd, "time"))        {            time_t t;            t = time(NULL);            printf("today is 2017/09/27/%ld\n", t);        }        else if(!strcmp(cmd, "name"))        {            printf("my name is Zhang Jiawei\n");        }        else if(!strcmp(cmd, "teacher"))        {            printf("the teacher is Meng Ning~\n");        }        else if(!strcmp(cmd, "dance"))        {            printf("dance~dance~dance~\n");        }        else if(!strcmp(cmd, "happy"))        {            printf("i am so happy!\n");        }        else if(!strcmp(cmd, "hungry"))        {            printf("i am so hungry,please exit~~\n");        }        else         {            printf("input an error~\n");        }    }}

进行编译运行如下:

gcc cmd.c -o cmd./cmd

demo

第三步:提交到git

git add cmd.cgit commit -m "the cmd program"git push

总结

通过这次实验让我知道了如何规范的写代码,形成良好的代码风格,为以后的进步打下良好的基础。也对git的操作进行了温习。

代码测试

git clone http://github/zjw121461745/se_lab2.gitcd se_lab2ls -a gcc cmd.c -o cmd./cmd
原创粉丝点击