Linux|c语言

1、Makefile

在代码编写中,我们经常看见多个源文件一起使用,在项目中很多时候将就规范使用各部分文件。进行源码封装。但是在linux中函数多个.c文件怎么让他们产生关系呢?让程序运行时就可以多个文件一起使用。这就会有make、Makefile来实现。Makefile内部产生文件依赖,让其产生耦合。实现函数联合。Makefile是一个依赖关系和依赖方法构建的自动化编译的工具。
具体实现

mytest:test.c//创建依赖关系
	gcc -o mytest test.c
.PHONY:clean
clean:
	rm -f mytest

在linux中使用指令

make Makefile

就可以创建Makefile文件,文件中可以自己添加文件关联项,.h文件不需添加其中,编译器会在当前文件目录中自己寻找。也可以使用指令

ls>Makefile

就可以实现Makefile创建和依赖关系文件创建。

2、进度条展示

应该具有对于\r 、\n区分,前者是让指令进行从头答应。后者就是熟悉的换行操作。有了对于这个指令的区分就可以实现
在这里插入图片描述
代码如下

  1#include<stdio.h>
  3 #include "pro.h"
  4 #include <string.h>
  5 #include <unistd.h>
  6 
  7 #define SIZE 102
  8 #define STYLE '='
  9 #define ARR '>'
 10 
 11 void process()
 12 {
    
    
 13     const char *lable = "|/-\\";
 14     char bar[SIZE];
 15     memset(bar, '\0', sizeof(bar));
 16     int i = 0;
 17     while( i <= 100 )
 18     {
    
    
 19         printf("[%-100s][%d%%][%c]\r", bar, i, lable[i%4]);                                                                                                                            
 20         fflush(stdout);
 21         bar[i++] = STYLE;
 22         if(i != 100) bar[i] = ARR;
 23         usleep(100000);
 24     }
 25     printf("\n");
 26  printf("\n");
 27 }
~

猜你喜欢

转载自blog.csdn.net/github_73587650/article/details/129449727