共用方式為


putc、putwc

將一個字元寫入資料流。

int putc( 
   int c, 
   FILE *stream  
); 
wint_t putwc( 
   wchar_t c, 
   FILE *stream  
);

參數

  • c
    待寫入字元。

  • stream
    指向 FILE 結構的指標。

傳回值

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

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

備註

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

具有 _nolock 結尾的版本除了不會防止被其他執行緒干擾之外都一樣。 如需詳細資訊,請參閱 _putc_nolock, _putwc_nolock

一般文字常式對應

TCHAR.H 常式

未定義 _UNICODE & _MBCS

已定義 _MBCS

已定義 _UNICODE

_puttc

putc

putc

putwc

需求

常式

必要的標頭

putc

<stdio.h>

putwc

<stdio.h> 或 <wchar.h>

Windows 市集 應用程式不支援主控台。 與主控台關聯的標準資料流控制代碼 (stdin、stdout 和 stderr) 必須重新導向,然後 C 執行階段函式才能在 Windows 市集 應用程式中使用它們。 如需其他相容性資訊,請參閱相容性

程式庫

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

範例

// crt_putc.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;
   /* Make standard out the stream and write to it. */
   stream = stdout;
   for( p = buffer; (ch != EOF) && (*p != '\0'); p++ )
      ch = putc( *p, stream );
}

Output

This is the line of output

.NET Framework 對等用法

請參閱

參考

資料流 I/O

fputc、fputwc

getc、getwc