日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

文件操作(stat)

發布時間:2023/11/30 编程问答 25 豆豆
生活随笔 收集整理的這篇文章主要介紹了 文件操作(stat) 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
/*** stat.c ***/ #include<stdio.h> #include<string.h> #include<sys/stat.h> #include<stdlib.h>int main() {struct stat st = {0}; //定義一個結構體,名字叫ststat("./a.txt",&st); //調用完stat函數之后,文件的相關信息就保存再st結構中char *array = malloc(st.st_size); //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); }

?可以使用時間相關函數來計算一下程序運行的時間

#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); }

?

轉載于:https://www.cnblogs.com/wanghao-boke/p/11233900.html

總結

以上是生活随笔為你收集整理的文件操作(stat)的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。