共用方式為


putchar、putwchar

寫入一個字元給 stdout

int putchar( 
   int c  
); 
wint_t putwchar( 
   wchar_t c  
);

參數

  • c
    待寫入字元。

傳回值

傳回寫入的字元。 若要表示錯誤或文件關閉條件, putcputchar 會傳回 EOFputwcputwchar 傳回 WEOF。 對於所有四個常式,請使用 ferrorfeof 來檢查錯誤或檔案結尾。 如果傳遞一個 null 指標給 stream,這些函式會產生一個無效的參數例外狀況,如 參數驗證 中所述。 如果允許繼續執行,它們會傳回 EOFWEOF,並將 errno 設定為EINVAL

如需更多關於這些和其他回傳碼的資訊,請參閱 _doserrno 、 errno 、 _sys_errlist 和 _sys_nerr (_doserrno, errno, _sys_errlist, and _sys_nerr)

備註

putc 常式給輸出 stream 的目前位置寫入單一字元 c。 任何整數可以傳遞至 putc,但只有較低 8 位元組會寫入。 putchar 常式和 putc( c**、stdout )**都相同。 對於每個常式,,如果讀取錯誤發生,資料流的錯誤指示器會被設定。 putcputchar 分別是類似於 fputc_fputchar,但是都會被實作為函式和巨集 (請參閱 選取函式和巨集之間)。 putwcputwchar 分別為 putcputchar 的寬字元版本。

_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 市集 應用程式中使用它們。 如需其他相容性資訊,請參閱相容性

程式庫

C 執行階段程式庫的所有版本。

範例

// 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

.NET Framework 對等用法

請參閱

參考

資料流 I/O

fputc、fputwc

getc、getwc