• 在Linux下用make指令编译进度条程序。


    首先建立一个新的文件,touch progress_bar.c 运行该vim progress_bar.c命令。写进度条的程序。

    写进一个进度条程序:

    #include<stdio.h>
    #include<unistd.h>
    #include<string.h>
    
    void progress()
    {
        int i = 0;
        char bar[102];
        memset(bar,0,102*sizeof(char));
        const char* lable="|/-\";
        while(i <= 100)
        {
            bar[i] = '#';    
            printf("[%-101s] [%d%%] [%c]",bar,i,lable[i%4]);
            fflush(stdout);
            usleep(100000);
            i++;
        }
        printf("
    ");
    }
    
    int main()
    {
        progress();
        return 0;
    }

    如图:
    这里写图片描写叙述

    该代码中须要注意的小细节:
    1. const char* lable=”|/-\”; 直接输入一个会被系统觉得是转义。所以要输入\
    2. printf(“[%-101s] [%d%%] [%c]”,bar,i,lable[i%4]);这里的%%同上,防止转义。i%4防止溢出
    3. fflush(stdout); 參数为标准输出流
    4. 由于sleep默认单位为秒。不便于測试,usleep默认单位为微秒
    最后,进行调试,建立一个mymakefile文件,touch mymakefile对该文件进行编辑vim mymakefile。

    myprogress_bar:progress_bar.c
        g++ -o myprogress_bar progress_bar.c
    :PHONY clean
        clean:
        rm -f myprogress_bar

    如图所看到的:

    然后运行make命令,对progress_bar.c文件进行编译,make -f mymakefile,即生成myprogress_bar文件。用./myprogress_bar对他进行运行。若想又一次进行编译。则须要make -f mymakefile clean指令。先对文件progress_bar进行清除,再用make进行编译。
    如图:
    这里写图片描写叙述

  • 相关阅读:
    实现AB值对换的两种方法
    Spring文件上传Demo
    CentOS 查看系统 CPU 个数、核心数、线程数
    InvocationTargetException异常
    在 Excel 中设置图片
    JavaScript写入文件到本地
    Semaphore初探
    MySQL连接服务端的几种方式
    超链接导致window.location.href失效的解决办法
    在 CentOS7 上安装 swftools
  • 原文地址:https://www.cnblogs.com/liguangsunls/p/7366902.html
Copyright © 2020-2023  润新知