建立檔案與刪除檔案的小例子

2022-09-17 02:51:12 字數 2210 閱讀 8256

在單目錄下建立和刪除大量1位元組的檔案所需的時間進行度量,檔名以xnnnnnn的格式來建立。數量在1000-20000之間。建立時隨機,刪除時按照檔名公升序。

暫時還沒有想出來該如何儲存隨機數組中的內容,執行兩次函式後,隨機數組的內容就變了。只能簡單的用difftime()來簡略的度量時間.

1 #include "

head.h"2

void create (int a,int

num);

3void delete(int a,int

num);

4void bubble_sort(int a,int

num);

5int k[20000]=;

6int main(int argc,char *ar**)78

15int flag=atoi(ar**[1

]);16

int num=atoi(ar**[2

]);17

if(num>19000

)18 num=num-1000;19

int *a=calloc(num,sizeof(int

));20

//int *k=calloc(num,sizeof(int));

21int i=0

;22 srand((unsigned int

)time (null));

23time_t start ,end;

24double

diff;

25/*

if(flag==1)

26

32//time(&start);

33create(a,num);

34//time(&end);35}

36int m=0;

37for(i=0;i38

41if(flag==0)

4249

free(a);

*/50

for(i=0;i)

51

55 time(&start);

56create(a,num);

57 time(&end);

5859 diff=difftime(end,start);

60 printf("

建立%d個檔案,耗時:%.2f秒\n

",num,diff);

61bubble_sort(a,num);

62 time(&start);

63delete(a,num);

64 time(&end);

65 diff=difftime(end,start);

66 printf("

刪除%d個檔案,耗時:%.2f秒\n

",num,diff);

6768

return0;

69}7071

void create (int a,int

num)

72 90}

91void delete(int a,int

num)

92100

}101

void bubble_sort(int a,int

num)

102114

}115

}116 }

head.h

1 #include 2 #include 3 #include 4 #include 5 #include 6 #include 7 #include 

8 #include 9 #include 10 #include 11 #include 12 #include 13 #include 14 #include 15 #include 16 #include17 #include 18 #include19 #include 20 #include 21 #include 22 #include 23 #include 24 #include 25 #include in.h>

26 #include 27 #include 28 #include 29 #include 30

void strerr(const

char *msg)

3135

void err(const

char *msg)

36

C 建立資料夾,刪除資料夾,建立檔案,刪除檔案

protected void button1 click object sender,eventargs e 判斷檔案的存在 else string name getfiles.filename 獲取已上傳檔案的名字 string size getfiles.postedfile.contentle...

建立檔案,檔案讀取與顯示

usr bin env python maketextfile.py create text file import os ls os.linesep get filename while true fname raw input enter filename if os.path.exists f...

centos徹底刪除資料夾建立檔案

centos徹底刪除資料夾 檔案命令 centos 新建 刪除 移動 複製等命令 1.新建資料夾 mkdir 檔名 新建乙個名為test的資料夾在home下 view source1 mkdir home test 2.新建文字 在home下新建乙個test.sh指令碼 vi home test.s...