putchar putwchar
提供 stdout將字元。
int putchar(
int c
);
wint_t putwchar(
wchar_t c
);
參數
- c
要寫入的字元。
傳回值
傳回寫入的字元。 表示錯誤或文件關閉條件, putc 和 putchar 會傳回 EOF; putwc 和 putwchar 傳回 WEOF。 對於所有四個常式,請使用 ferror 或 feof 來檢查錯誤或檔案結尾。 如果傳遞 stream的 null 指標,則這些函式產生無效參數例外狀況,如 參數驗證中所述。 如果執行允許繼續執行,則會傳回 EOF 或 WEOF 並將 errno 設為 EINVAL。
如需更多關於這些和其他回傳碼的資訊,請參閱 _doserrno 、 errno 、 _sys_errlist 和 _sys_nerr (_doserrno, errno, _sys_errlist, and _sys_nerr) 。
備註
putc 常式給輸出 stream 寫入單一字元 c 中目前的位置。 任何整數可以傳遞至,則為 putc,但只下 8 位元組寫入。 putchar 常式 putc(c, 和 **stdout )**都相同。 對於每個常式,,如果讀取錯誤,資料流的錯誤指示器設定。 putc 和 putchar 分別是類似於 fputc 和 _fputchar,,,但是會實作為函式和當做巨集 (請參閱 選取函式和巨集之間)。 putwc 和 putwchar 分別為 putc 和 putchar,寬字元版本。
與 _nolock 結尾的版本相同,但不會防止由其他執行緒的功能。 因為它們不會造成額外負荷鎖定其他執行緒,可能會比較快。 在安全執行緒內容中只使用這些函式 (例如單一執行緒應用程式呼叫或的範圍控制代碼已經執行緒隔離的地方。
泛用文字常式對應
TCHAR.H 常式 |
未定義 _UNICODE & _MBCS |
已定義 _MBCS |
已定義 _UNICODE |
---|---|---|---|
_puttchar |
putchar |
putchar |
putwchar |
需求
程序 |
必要的標頭檔 |
---|---|
putchar |
<stdio.h> |
putwchar |
<stdio.h> 或 <wchar.h> |
主控台 Windows 市集 應用程式不支援。 標準資料流控制代碼與主控台, stdin, stdout和 stderr,在這種情況下, C 執行階段函式在 Windows 市集 應用程式之前,可以使用它們必須重新導向。 如需其他相容性資訊,請參閱入門介紹中的 相容性 (Compatibility) 。
程式庫
所有的 C 執行階段程式庫 (C run-time libraries) 版本。
範例
// crt_putchar.c
/* This program uses putc to write buffer
* to a stream. If an error occurs, the program
* stops before writing the entire buffer.
*/
#include <stdio.h>
int main( void )
{
FILE *stream;
char *p, buffer[] = "This is the line of output\n";
int ch;
ch = 0;
for( p = buffer; (ch != EOF) && (*p != '\0'); p++ )
ch = putchar( *p );
}
Output
This is the line of output