Linux C學習筆記 txt檔案讀寫

2021-08-31 13:34:30 字數 2045 閱讀 9620

/***************

perror(s) 用來將上乙個函式發生錯誤的原因輸出到標準裝置(stderr)。引數 s 所指的字串會先列印出,後面再加上錯誤原因字串。此錯誤原因依照全域性變數errno的值來決定要輸出的字串。

file * fopen(const char * path, const char * mode);返回值:檔案順利開啟後,指向該流的檔案指標就會被返回。如果檔案開啟失敗則返回 null,並把錯誤**存在 error 中。

fgetc()fgetc是一種計算機語言中的函式。意為從檔案指標stream指向的檔案中讀取乙個字元,讀取乙個位元組後,游標位置後移乙個位元組。格式:int fgetc(file *stream);。

fputc()將字元ch寫到檔案指標fp所指向的檔案的當前寫指標的位置。函式格式:int fputc (int c, file *fp)。

exit()  exit(0) 表示程式正常退出,exit⑴/exit(-1)表示程式異常退出。

pid_t wait (int * status);如果執行成功則返回子程序識別碼(pid),如果有錯誤發生則返回-1。失敗原因存於errno 中。

fprintf是c/c++中的乙個格式化寫—庫函式,位於標頭檔案中,其作用是格式化輸出到乙個流/檔案中;

函式原型為int fprintf( file *stream, const char *format, [ argument ]...),fprintf()函式根據指定的格式(format)向輸出流(stream)寫入資料(argument)。

*/

#include #include #include #include using namespace std;

/***************

perror(s) 用來將上乙個函式發生錯誤的原因輸出到標準裝置(stderr)。引數 s 所指的字串會先列印出,後面再加上錯誤原因字串。此錯誤原因依照全域性變數errno的值來決定要輸出的字串。

file * fopen(const char * path, const char * mode);返回值:檔案順利開啟後,指向該流的檔案指標就會被返回。如果檔案開啟失敗則返回 null,並把錯誤**存在 error 中。

fgetc()fgetc是一種計算機語言中的函式。意為從檔案指標stream指向的檔案中讀取乙個字元,讀取乙個位元組後,游標位置後移乙個位元組。格式:int fgetc(file *stream);。

fputc()將字元ch寫到檔案指標fp所指向的檔案的當前寫指標的位置。函式格式:int fputc (int c, file *fp)。

exit() exit(0) 表示程式正常退出,exit⑴/exit(-1)表示程式異常退出。

pid_t wait (int * status);如果執行成功則返回子程序識別碼(pid),如果有錯誤發生則返回-1。失敗原因存於errno 中。

fprintf是c/c++中的乙個格式化寫—庫函式,位於標頭檔案中,其作用是格式化輸出到乙個流/檔案中;

函式原型為int fprintf( file *stream, const char *format, [ argument ]...),fprintf()函式根據指定的格式(format)向輸出流(stream)寫入資料(argument)。

*/int main()

fclose(fp);

printf("upper count:%d\n",count);

fprintf(wp,"upper:%d\n",count);

exit(0);

}else

fclose(fp);

printf("lower count:%d\n",count);

fprintf(wp,"lower:%d\n",count);

fclose(wp);}}

file* rp = fopen("out.txt","r");

if(rp == null)

perror("rp error");

int c;

while((c = getc(rp))!= eof)

return 0;

}

TXT檔案學習筆記

一 標頭檔案 include shlwapi.h pragma comment lib,shlwapi.lib 新增相應的lib庫,pathfileexists 函式需要,這個pathfileexists 函式用於測試資料夾是否已存在 include c 檔案io頭 include include ...

Linux C 學習筆記

1.linux 程序與訊號 檢視當前系統所有程序的shell命令 ps aux 檢視程序樹 pstree 檢視當前使用者啟動的程序 ps af kill 程序號 kill 9 程序號 強行殺死程序 killall 程序名字 如果乙個程序的父程序被殺死 則init就程式設計當前程序的父程序 了解實時作...

linux C 學習筆記(二) 底層檔案訪問

檔案描述符 0 標準輸入 1 標準輸出 2 標準錯誤 系統呼叫 write 把緩衝區buf的前nbytes個位元組寫入與檔案描述符fildes關聯的檔案中,返回實際寫入的位元組數。include size t write int fildes,const void buf,size t nbytes...