_getw

Gets an integer from a stream.

int_getw(FILE*stream);

Routine Required Header Compatibility
_getw <stdio.h> Win 95, Win NT

For additional compatibility information, see Compatibility in the Introduction.

Libraries

LIBC.LIB Single thread static library, retail version
LIBCMT.LIB Multithread static library, retail version
MSVCRT.LIB Import library for MSVCRT.DLL, retail version

Return Value

_getw returns the integer value read. A return value of EOF indicates either an error or end of file. However, because the EOF value is also a legitimate integer value, use feof or ferror to verify an end-of-file or error condition.

Parameter

stream

Pointer to FILE structure

Remarks

The _getw function reads the next binary value of type int from the file associated with stream and increments the associated file pointer (if there is one) to point to the next unread character. _getw does not assume any special alignment of items in the stream. Problems with porting may occur with _getw because the size of the int type and the ordering of bytes within the int type differ across systems.

Example

/* GETW.C: This program uses _getw to read a word
 * from a stream, then performs an error check.
 */

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

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

   if( (stream = fopen( "getw.c", "rb" )) == NULL )
      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( stream );
      }
      else
         printf( "First data word in file: 0x%.4x\n", i );
      fclose( stream );
   }
}

Output

First data word in file: 0x47202a2f

Stream I/O Routines

See Also   _putw