getc 中文man頁面

2021-01-08 51cto

NAME

fgetc, fgets, getc, getchar, gets, ungetc - 輸入字符和字符串  

總覽 (SYNOPSIS)

#include <stdio.h>int fgetc(FILE *stream);char *fgets(char *s, int size, FILE *stream);int getc(FILE *stream);int getchar(void);char *gets(char *s);int ungetc(int c, FILE *stream);

描述 (DESCRIPTION)

fgetc() 從 stream 流 中 讀取 下一個 字符, 然後 從 unsigned char 類型轉換 到 int 型 返回, 如果 到達 文件末尾 或 出現 錯誤 則 返回 EOF .

getc() 等於 fgetc() , 只是 它 可能 以 宏 的 形式 實現, 並 多次 訪問 stream 流.

getchar() 等於 getc(stdin).

gets() 從 stdin 讀取 一行 字符串, 保存在 s 指向的 緩衝區 中, 讀到 換行符(newline) 或 EOF 時 操作 結束, 同時 把 它們 替換為 '\0'. 該函數 不檢查 緩衝區溢出 (參見 後面的 BUGS 節).

fgets() 從 stream 流 中 讀取 多至 size - 1 個 字符, 保存在 s 指向的 緩衝區 中, 讀到 換行符(newline) 或 EOF 時 操作 結束, 如果 讀到的 是 換行符, 把 換行符 也保存在 緩衝區 中. 函數 將在 最後一個 字符 後面 添加 一個 '\0' 字符.

ungetc() 把 c 轉換為 unsigned char 類型 並 回送到 stream 中 供 後續的 讀操作 讀取. 回送的 所有 字符 將按 相反的 順序 返回; 只保證 一個 回送 操作 的 可靠.

這裡 描述的 函數 可以 混合 使用, 也可以 結合 stdio 庫中 其他的 輸入函數 處理 同一個 輸入流.

相應的 無鎖函數(non-locking) 參見 unlocked_stdio(3).

返回值 (RETURN VALUE)

fgetc(), getc() 和 getchar() 返回 從 unsigned char 類型轉換 到 int 型 的 字符, 如果 操作 失敗 或 到達 文件末尾 則 返回 EOF .

如果 操作 成功, gets() 和 fgets() 返回 s 指針, 否則 返回 NULL 指針, 如果 到達 文件末尾 時 還沒有 讀到 字符 也返回 NULL .

操作 成功 時 ungetc() 返回 c , 否則 返回 EOF .

遵循 (CONFORMING TO)

ANSI - C, POSIX.1

BUGS

永遠 不要 使用 gets(). 由於 gets() 事先 不知道 數據內容, 因此 不可能 知道 應該 讀取 多少 字符, 而且 gets() 會 連續 接收 字符, 即使 越過 緩衝區 的 末尾 也 不停止, 所以 這個 函數 非常危險. 它 曾經 被用來 破壞 計算機系統 的 安全. 用 fgets() 代替.

建議 不要 混合 stdio 庫的 輸入函數 和 低層 read() 函數 對 輸入流 對應 文件描述符 的 調用; 其 結果 沒有 定義, 極可能不是 你 需要的.

另見 (SEE ALSO)

read(2), write(2), ferror(3), fopen(3), fread(3), fseek(3), puts(3), scanf(3), unlocked_stdio(3)

NAME

fgetc, fgets, getc, getchar, gets, ungetc - input of characters and strings  

SYNOPSIS

#include <stdio.h>int fgetc(FILE *stream);char *fgets(char *s, int size, FILE *stream);int getc(FILE *stream);int getchar(void);char *gets(char *s);int ungetc(int c, FILE *stream);

DESCRIPTION

fgetc() reads the next character from stream and returns it as an unsigned char cast to an int, or EOF on end of file or error.

getc() is equivalent to fgetc() except that it may be implemented as a macro which evaluates stream more than once.

getchar() is equivalent to getc(stdin).

gets() reads a line from stdin into the buffer pointed to by s until either a terminating newline or EOF, which it replaces with '\0'. No check for buffer overrun is performed (see BUGS below).

fgets() reads in at most one less than size characters from stream and stores them into the buffer pointed to by s. Reading stops after an EOF or a newline. If a newline is read, it is stored into the buffer. A '\0' is stored after the last character in the buffer.

ungetc() pushes c back to stream, cast to unsigned char, where it is available for subsequent read operations. Pushed - back characters will be returned in reverse order; only one pushback is guaranteed.

Calls to the functions described here can be mixed with each other and with calls to other input functions from the stdio library for the same input stream.

For non-locking counterparts, see unlocked_stdio(3).  

RETURN VALUE

fgetc(), getc() and getchar() return the character read as an unsigned char cast to an int or EOF on end of file or error.

gets() and fgets() return s on success, and NULL on error or when end of file occurs while no characters have been read.

ungetc() returns c on success, or EOF on error.  

CONFORMING TO

ANSI - C, POSIX.1. LSB deprecates gets().  

BUGS

Never use gets(). Because it is impossible to tell without knowing the data in advance how many characters gets() will read, and because gets() will continue to store characters past the end of the buffer, it is extremely dangerous to use. It has been used to break computer security. Use fgets() instead.

It is not advisable to mix calls to input functions from the stdio library with low - level calls to read() for the file descriptor associated with the input stream; the results will be undefined and very probably not what you want.  

SEE ALSO

read(2), write(2), ferror(3), fopen(3), fread(3), fseek(3), puts(3), scanf(3), unlocked_stdio(3)

【責任編輯:

韓亞珊

TEL:(010)68476606】

相關焦點

  • getchar 中文man頁面
    NAMEfgetc, fgets, getc, getchar, gets, ungetc - 輸入字符和字符串  總覽 (SYNOPSIS)#include <stdio.h>int fgetc(FILE *stream
  • man.conf 中文man頁面
    man.conf 中文man頁面 man(1) man(1) 會 讀 取 本 檔 。man.conf 的 內 容 包 含 了 (a) 如 何 建 立 man 搜 尋 路 徑 的 資 訊 , (b) man 所 使 用 的 程 式 ( nroff, egn, tbl 等 等 ) 的 完 整 路 徑 設 定 (c) 對 特 定 副 檔 名 的 解 壓 縮 程 式 。
  • securetty 中文man頁面
    securetty 中文man頁面 /etc/securetty 由 login(1) 使用,該文件由包含數行 tty 設備名(每行一個設備名,前面不加 /dev/) 在這些設備上可以允許 root 登錄.
  • ROLLBACK 中文man頁面
    ROLLBACK 中文man頁面 ROLLBACK 回卷當前事務並取消當前事務中的所有更新。
  • CHECKPOINT 中文man頁面
    CHECKPOINT 中文man頁面 預寫式日誌(Write-Ahead Logging (WAL))預設時在事務日誌中每隔一段時間放一個檢查點。
  • su 中文man頁面
    su 中文man頁面 su - 運行替換用戶和組標識的shell。
  • DROP INDEX 中文man頁面
    DROP INDEX 中文man頁面 DROP INDEX 從資料庫中刪除一個現存的索引。 要執行這個命令,你必須是索引的所有者。
  • START TRANSACTION 中文man頁面
    START TRANSACTION 中文man頁面 這條命令開始一個新的事務。如果聲明了隔離級別或者讀寫模式, 那麼新事務就使用這個特性,如同執行了 SET TRANSACTION [set_transaction(7)] 一樣。
  • col 中文man頁面
    col 中文man頁面 Col 過濾掉反向(以及半反向)換行符(LF: line feed or NL: new line), 這樣輸出按正常順序,即只包括正向和半正向換行符, 而且在可能的地方使用tab替換白空格.這對 nroff(1) 和 tbl(1) 的輸出處理很有用處.
  • IRONMAN中文官網正式上線,報名中國賽再無語言障礙!
    網址:http://www.ironman-china.com (點擊文章左下角閱讀原文即可跳轉)IRONMAN中文官網界面沿用了國際版的頁面設計,與此同時還加入了濃濃的中國元素,頁面主題更加簡潔鮮明、功能更加實用多樣。
  • 《lol手遊》設置頁面中文翻譯圖一覽 設置頁面中文對照表一覽
    導 讀 英雄聯盟手遊目前已經在外服開始正式上線,很多國內的玩家也登陸日服進行體驗,不過由於界面都是日文或者英文,導致玩家對於設置上的內容不了解,很影響遊戲體驗,下面就讓寒山介紹一下英雄聯盟手遊的設置頁面翻譯
  • pppd 中文man頁面
    Username/Password Incorrect" "" "at" OK "at&d0&c1" OK "atdt2468135" "name:" "^Umyuserid" "word:" "\qmypassword" "ispts" "\q^Uppp" "~-^Uppp-~" See the chat(8) man
  • putc 中文man頁面
  • icmp 中文man頁面
  • read 中文man頁面
  • fifo 中文man頁面
  • modinfo 中文man頁面
  • fflush 中文man頁面
  • stdin 中文man頁面
  • setvbuf 中文man頁面