_getw

從資料流中取得的整數。

語法

int _getw(
   FILE *stream
);

參數

stream
FILE 結構的指標。

傳回值

_getw 傳回讀取的整數值。 傳回值為 EOF 表示錯誤或檔案結尾。 不過,因為 EOF 值也是合法的整數值,所以請使用feofferror 來確認檔案結尾或錯誤狀況。 如果 streamNULL ,則會叫用不正確參數處理常式,如參數驗證 中所述 。 若允許繼續執行, errno 會設為 EINVAL ,且函式會傳回 EOF中所述。

備註

_getw 式會從相關聯的 stream 檔案讀取類型的 int 下一個二進位值,並遞增相關聯的檔案指標(如果有的話),以指向下一個未讀取的字元。 _getw 不會假設資料流程中專案的任何特殊對齊方式。 _getw 可能會發生移植的問題,因為 int 類型的大小和 int 類型內位元組順序於不同系統間有差異。

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

需求

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

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

範例

// crt_getw.c
// This program uses _getw to read a word
// from a stream, then performs an error check.

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

int main( void )
{
   FILE *stream;
   int i;

   if( fopen_s( &stream, "crt_getw.txt", "rb" ) )
      printf( "Couldn't open file\n" );
   else
   {
      // Read a word from the stream:
      i = _getw( stream );

      // If there is an error...
      if( ferror( stream ) )
      {
         printf( "_getw failed\n" );
         clearerr_s( stream );
      }
      else
         printf( "First data word in file: 0x%.4x\n", i );
      fclose( stream );
   }
}

輸入︰crt_getw.txt

Line one.
Line two.

輸出

First data word in file: 0x656e694c

另請參閱

資料流 I/O
_putw