1. C语言中的改变文件大小的函数
但C语言如果调用命令获取命令结果,需要以popen(char* command, char* buf)来取得结果,比较不方便,经一番搜寻,发现C语言本身的函数就可以解决这一问题。
解决办法:
1. 使用stat()编写自定义的函数get_file_size();
static int get_file_size(const char* file) {
struct stat tbuf;
stat(file, &tbuf);
return tbuf.st_size;
}
使用示例:
#include <stdio.h>
#include <sys/stat.h>
#include <unistd.h>
static int get_file_size(const char* file) {
struct stat tbuf;
stat(file, &tbuf);
return tbuf.st_size;
}
int main() {
struct stat buf;
stat("./test.log", &buf);
printf("test.log file size = %d \n", (int)buf.st_size);
printf("test.log file size is: %d \n", get_file_size("./test.log"));
return 0;
}
编译:
hxtc@hxtc-pd:~/work/debug/c_debug/src/c_exer$ gcc -std=gnu99 -o test_stat test_stat.c
运行结果:
hxtc@hxtc-pd:~/work/debug/c_debug/src/c_exer$ ./test_stat
test.log file size = 8358940
test.log file size is: 8358940
2. C语言如何写超过2G大小的文件
将 =top#源反编译 重复翻倍 直到超过1G然后再反编译翻倍 2G以上就有了