文件操作(stat)
生活随笔
收集整理的這篇文章主要介紹了
文件操作(stat)
小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.
/***
stat.c
***/
#include<stdio.h>
#include<string.h>
#include<sys/stat.h>
#include<stdlib.h>int main()
{struct stat st = {0}; //定義一個(gè)結(jié)構(gòu)體,名字叫ststat("./a.txt",&st); //調(diào)用完stat函數(shù)之后,文件的相關(guān)信息就保存再st結(jié)構(gòu)中char *array = malloc(st.st_size); //st.st_size 表示文件的大小,在堆中動(dòng)態(tài)分配一塊文件大小的內(nèi)存FILE *p = fopen("./a.txt","rb");fread(array,sizeof(char),st.st_size,p); //相當(dāng)于把整個(gè)文件一下子放入內(nèi)存中
fclose(p);p = fopen("./b.txt","wb");fwrite(array,sizeof(char),st.st_size,p); //將堆中的信息一下寫入文件中
fclose(p);
}
?可以使用時(shí)間相關(guān)函數(shù)來(lái)計(jì)算一下程序運(yùn)行的時(shí)間
#include<stdio.h> #include<string.h> #include<sys/stat.h> #include<stdlib.h> #include<time.h>int main() {clock_t c1 = clock();struct stat st = {0};stat("./a.txt",&st);char *array = malloc(st.st_size);FILE *p = fopen("./a.txt","rb");fread(array,sizeof(char),st.st_size,p);fclose(p);p = fopen("./b.txt","wb");fwrite(array,sizeof(char),st.st_size,p);fclose(p);clock_t c2 = clock();printf("%u\n",c2-c1); }?
轉(zhuǎn)載于:https://www.cnblogs.com/wanghao-boke/p/11233900.html
總結(jié)
以上是生活随笔為你收集整理的文件操作(stat)的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。
- 上一篇: 江南百景图烟熏肉在哪
- 下一篇: 战时我们正年少剧情介绍