UNIX環境高階程式設計學習筆記三 標準I O庫的介紹

2021-10-08 22:32:46 字數 1920 閱讀 4551

#include

#include

intfwid

(file *fp,

int mode)

;//指定流寬頻

void

setbuf

(file *restrict fp,

char

*restrict buf)

;//開啟或關閉緩衝機制

void

setvbuf

(file *restrict fp,

char

*restrict buf,

int mode, size_t size)

;//更改緩衝模式

/* mode 引數:

_iofbf 全緩衝

_iolbf 行緩衝

_ionbf 不帶緩衝

*/int

fflush

(file *fp)

;//更新緩衝區

file *

fopen

(const

char

*restrict pathname,

const

char

*restrict type)

;//開啟標準i/o流

intfclose

(file *fp)

;//關閉標準i/o流

int

snprintf

(char

*restrict buf, size_t n,

const

char

*restrict format,..

.);

#include

char

*tempnam

(char

*ptr)

;//建立有效路徑名

file *

tempfile

(void);

//建立檔案

/*以上存在缺點,及返回目錄和建立檔案期間有乙個時間缺口,可能會重複建立*/

/*替代函式*/

char

*mkdtemp

(char

*template)

;//建立目錄

intmkstemp

(char

*template)

;//建立檔案

操作函式:

#include

#include

file *

fmemopen

(void

*restrict buf, size_t size,

const

char

*restrict type)

;file *

open_memstream

(char

**bufp, size_t *sizep)

;file *

open_wmemstream

(wchar_t *

*bufp, size_t *sizep)

;

注意點:

一:fmemopen函式在緩衝區第乙個字元處設定null,必須使用fflush等函式才能輸出。

二:buf引數用null指標無意義,我們無法獲取fmemopen自動分配的位址來對資料進行操作。

三:使用fclose, fflush, fseek, fseeko及fsetpos時都會在當前位置加null

#include

"apue.h"

#define bsz 48

intmain()

5.6 程式自動輸出提示資訊的原因

在互動式程式中,使用行緩衝,每次呼叫 fgets() 時系統自動沖刷緩衝區。

UNIX環境高階程式設計學習筆記

include include include include int main int argc,char argv err sys can t open s argv 1 while dirp readdir dp null printf s n dirp d name closedir dp ...

UNIX環境高階程式設計學習筆記 程序

2.程序控制 在提出這個問題的時候,我想了一下,大概就是核心執行的乙個程式 錯誤回答 吧。但是這麼說,連我自己下次看都不明白在說什麼。於是我查了一下,它代表著cpu所能處理的單個任務,及執行例項。在面向程序設計的系統 如早期 unix,linux 2.4及更早版本中 程序是程式的基本執行實體 在面向...

Unix環境高階程式設計學習筆記 二

三種主要的標準 iso c ieee posix single unix specification xsi 一層一層遞增,ieee posix 是iso c的超集。xsi 是posix的超集。要想提高軟體的可移植性,就必須有限制 編譯時限制 因為某些限制是固定的,則可以在標頭檔案中定義。執行時限制...