函式名: fread
功 能: 從乙個流中讀資料
用 法: int fread(void *ptr, int size, int nitems, file *stream);
程式例:
#include
#include
int main(void)
/* write some data to the file */
fwrite(msg, strlen(msg)+1, 1, stream);
/* seek to the beginning of the file */
fseek(stream, seek_set, 0);
/* read the data and display it */
fread(buf, strlen(msg)+1, 1, stream);
printf("%s/n", buf);
fclose(stream);
return 0;
} 函式名: fwrite
功 能: 寫內容到流中
用 法: int fwrite(void *ptr, int size, int nitems, file *stream);
程式例:
#include
struct mystruct
; int main(void)
s.i = 0;
s.ch = 'a';
fwrite(&s, sizeof(s), 1, stream); /* write struct s to file */
fclose(stream); /* close file */
return 0;
}
常用的檔案讀寫函式
一 函式原型 file fopen const char path,const char mode 功能 開啟乙個檔案 如果路徑下無此檔案,會新建立乙個 引數 path 檔案路徑 mode 開啟方式,有 w,w r,r a,a w 開啟只寫檔案,若檔案存在,則清空檔案內容,進行寫。檔案不存在則建立檔...
檔案讀寫操作的函式
筆記 include include include include intopen const char pathname,int flags intopen const char pathname,int flags,mode t mode int creat const char pathna...
mysql讀寫檔案函式 讀寫檔案 檔案方法 函式
讀寫檔案 全域性申明 import codecs encodeing utf 8 開啟檔案的模式有 r,唯讀模式 預設 w,只寫模式。不可讀 不存在則建立 存在則刪除內容 a,追加模式。可讀 不存在則建立 存在則只追加內容 表示可以同時讀寫某個檔案 r 可讀寫檔案。可讀 可寫 可追加 w 寫讀 a ...