乙個修改檔案中指定內容的程式

2022-09-22 22:33:23 字數 1003 閱讀 2735

下面是乙個修改檔案中指定內容的程式,這裡面主要用到了以下幾個函式:

file * fopen(const char * path,const char * mode);

size_t fread ( void *buffer, size_t size, size_t count, file *stream) ;

buffer:用於接收資料的記憶體位址;

size:要讀的每個資料項的大小,單位為位元組;

count:要讀的資料項的個數;

stream:輸入流。

size_t fwrite(const void* buffer, size_t size, size_t count, file* stream);

int fseek(file *stream, long offset, int fromwhere);

函式設定檔案指標stream的位置。如果執行成功,stream將指向以fromwhere(偏移起始位置:檔案頭0(seek_set),當前位置1(seek_cur),檔案尾2(seek_end))為基準,偏移offset(指標偏移量)個位元組的位置。如果執行失敗(比如offset超過檔案自身大小),則不改變stream指向的位置。

程式**如下:

#include

#include

#include

#include

int main()

//下面部分為寫檔案

/*int i = 0;

int j = 0;

for (i = 0;i < 1310720 ;++i)

*///下面部分為修改指定內容

char a;

int count = 0;

while(fread(&a,sizeof(char),1l,fd)==1)

}time_t endtime = time(null);

printf("time = %g\n",endtime-starttime);

}

C 替換檔案中指定的內容

實現替換檔案中指定的內容 created by cryking 2012.02.12 include include include includeusing namespace std char strstr rep char source,char old,char ne 字元替換 strstr...

Linux 檢視檔案中指定行數的內容

1 tail n 數字 檔名 2 head n 數字 檔名 3 sed n 開始行,結束行p 檔名 步驟一 cd 到要檔案所在目錄 cd到要檢視指定行數內容的檔案所在目錄,本文以specialvariable.sh檔案為例,cd home test shell 步驟二 tail n 數字 檔名 ta...

Java如何開啟乙個資料夾並選中指定檔案

很簡單,呼叫explorer.exe就可以,runtime.getruntime exec rundll32 shell32.dll,shellexec rundll explorer.exe select,targetdirectfilename windows explorer switches...