欢迎使用CSDN-markdown编辑器

豆子123第二次作业

Author: 张佳伟 SA17225491

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

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

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

git clone http://github.com/zjw121461745/se_lab2.git
cd se_lab2
vi 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.c
git commit -m "the cmd program"
git push

总结

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

代码测试

git clone http://github/zjw121461745/se_lab2.git
cd se_lab2
ls -a 
gcc cmd.c -o cmd
./cmd
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值