Share via


_putw

Writes an integer to a stream.

int_putw(intbinint**,FILE*stream);**

Routine Required Header Compatibility
_putw <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

_putw returns the value written. A return value of EOF may indicate an error. Because EOF is also a legitimate integer value, use ferror to verify an error.

Parameters

binint

Binary integer to be output

stream

Pointer to FILE structure

Remarks

The _putw function writes a binary value of type int to the current position of stream._putw does not affect the alignment of items in the stream, nor does it assume any special alignment. _putw is primarily for compatibility with previous libraries. Portability problems may occur with _putw because the size of an int and the ordering of bytes within an int differ across systems.

Example

/* PUTW.C: This program uses _putw to write a
 * word to a stream, then performs an error check.
 */

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

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

Output

Wrote ten words

Stream I/O Routines

See Also   _getw