_putw

將一個整數寫入資料流。

語法

int _putw(
   int binint,
   FILE *stream
);

參數

binint
要輸出的二進位整數。

stream
FILE 結構的指標。

傳回值

傳回寫入的值。 EOF 的傳回值可能表示錯誤。 因為 EOF 也是合法的整數值,所以請使用 ferror 驗證錯誤。 如果 stream 為 Null 指標,則會叫用不正確參數處理常式,如參數驗證 中所述 。 若允許繼續執行,此函式會將 errno 設為 EINVAL,並傳回 EOF

如需這些錯誤碼和其他錯誤碼的相關資訊,請參閱 errno_doserrno_sys_errlist_sys_nerr

備註

_putw 式會將 類型的 int 二進位值寫入資料流程的目前位置 _putw 不會影響資料流程中專案的對齊方式,也不會假設任何特殊的對齊方式。 _putw 主要是為了與先前的程式庫相容所提供。 因為 int 的大小與 int 內位元組的排序會因系統而有所不同,所以 _putw 可能會發生可攜性問題。

根據預設,此函式的全域狀態會限定于應用程式。 若要變更此行為,請參閱 CRT 中的全域狀態。

需求

常式 必要的標頭
_putw <stdio.h>

如需相容性詳細資訊,請參閱相容性

程式庫

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

範例

// crt_putw.c
/* This program uses _putw to write a
* word to a stream, then performs an error check.
*/

#include <stdio.h>
#include <stdlib.h>

int main( void )
{
   FILE *stream;
   unsigned u;
   if( fopen_s( &stream, "data.out", "wb" ) )
      exit( 1 );
   for( u = 0; u < 10; u++ )
   {
      _putw( u + 0x2132, stream );   /* Write word to stream. */
      if( ferror( stream ) )         /* Make error check. */
      {
         printf( "_putw failed" );
         clearerr_s( stream );
         exit( 1 );
      }
   }
   printf( "Wrote ten words\n" );
   fclose( stream );
}

輸出

Wrote ten words

另請參閱

資料流 I/O
_getw