日韩av黄I国产麻豆传媒I国产91av视频在线观看I日韩一区二区三区在线看I美女国产在线I麻豆视频国产在线观看I成人黄色短片

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 >

文件操作(stat)

發(fā)布時間:2023/11/30 40 豆豆
生活随笔 收集整理的這篇文章主要介紹了 文件操作(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 表示文件的大小,在堆中動態(tài)分配一塊文件大小的內存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)的全部內容,希望文章能夠幫你解決所遇到的問題。

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