Borland C++ reference

putw

raw OCR

Puts an integer on a stream.

Defined in header <stdio.h>

Syntax

#include <stdio.h>
int putw(int zv, FILE *stream);

Portability

DOSUNIXWindowsANSI CC++ only
■■■

Remarks

putw outputs the integer w to the given stream, putw neither expects nor causes special alignment in the file.

Return value

On success, putw returns the integer zv. On error, putw returns EOF. Because EOF is a legitimate integer, use terror to detect errors with putw.

See also

Example

#include <stdio.h>
#include <stdlib.h>
tdefine FNAME  "test.$$$"

int main (void)

   FILE *fp;
   int word;
   /* place the word  in a file */
   fp = fopen(FNAME,  "wb");
   if (fp == NULL)  (
      printf ("Error opening file %s\n", FNAME);
      exit(l);
   }
   word =94;
   putw(word,fp) ;
   if (ferror (fp))
       printf ("Error writing to file\n");
   else
       printf ("Successful write\n");
   fclose(fp);
   /* reopen the file  */
   fp = fopen(FNAME,  "rb");
   if (fp == NULL)  {
      printf ("Error opening file %s\n", FNAME);
      exit(l);
   }
   /* extract the word  */
   word = getw(fp) ;
   if (ferror(fp))
       printf ("Error reading file\n");
   else
       printf ("Successful read: word = %d\n", word)

   /* clean up */
   fclose(fp);
   unlink(FNAME);
   return 0;

Differences from modern implementations

Nothing recorded yet.

Modern references

These are search links, not yet checked by hand.