putw
int  putw ( int integer , FILE * stream );
stdio.h
  cplusplus.com  

Write an integer to a stream.
  Writes a binary integer of type int to the stream and increases its position indicator to point to the next character.
  putw assumes no alignment in the stream.
  Notice that the length of int type depends on systems and compilers so this may cause some porting problems.

Parameters.

integer
integer to be written.
stream
Pointer to an open file.

Return Value.
  On success the integer value written is returned.
  On error EOF is returned  

Portability.
  Not defined in ANSI-C, but supported by many compilers.
  Notice that the size of int may vary depending on system.

Example.

/* putw/getw example */
#include <stdio.h>

main()
{
  FILE * pFile;
  int i;

  pFile = fopen ("myfile.bin","wb+");
  putw (20,pFile);
  rewind (pFile);
  i=getw (pFile);
  printf ("The double of %d is %d.\n", i, i*2);
  return 0;
}
This example creates a binary file called myfile.bin and stores a numeric value on it. Then this value is retrieved and its double is printed. This is done to emphatize that the type used is of type int and not a string.

See also.
  getw, printf, fwrite


© The C++ Resources Network, 2000