This documentation is archived and is not being maintained.


Writes an integer to a stream.

int _putw(
   int binint,
   FILE *stream 


Binary integer to be output.
Pointer to FILE structure.

Return Value

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.


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.


Routine Required header Compatibility
_putw <stdio.h> Win 98, Win Me, Win NT, Win 2000, Win XP

For additional compatibility information, see Compatibility in the Introduction.


All versions of the C run-time libraries.


// 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( (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( "Wrote ten words\n" );
   fclose( stream );


Wrote ten words

See Also

Stream I/O Routines | _getw | Run-Time Routines and .NET Framework Equivalents