_getw

Description

Gets an integer from a stream.

#include <stdio.h>

int _getw( FILE *stream );

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. The _getw function does not assume any special alignment of items in the stream.

Return Value

The _getw function returns the integer value read. A return value of EOF may indicate an error or end-of-file. However, since the EOF value is also a legitimate integer value, feof or ferror should be used to verify an end-of-file or error condition.

Compatibility

Standards:UNIX

16-Bit:DOS, QWIN, WIN, WIN DLL

32-Bit:DOS32X

Use _getw for compatibility with ANSI naming conventions of non-ANSI functions. Use getw and link with OLDNAMES.LIB for UNIX compatibility.

The _getw function is provided primarily for compatibility with previous libraries. Note that portability problems may occur with _getw, since the size of the int type and the ordering of bytes within the int type differ across systems.

See Also

_putw

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: 0x2a2f