Borland C++ reference

getw

raw OCR

Gets integer from stream.

Defined in header <stdio.h>

Syntax

#include <stdio.h>
int getw(FILE *stream);

Portability

DOSUNIXWindowsANSI CC++ only
■■■

Remarks

getw returns the next integer in the named input stream. It assumes no special alignment in the file.

getw should not be used when the stream is opened in text mode.

Return value

getw returns the next integer on the input stream. On end-of-file or error, getw returns EOF. Because EOF is a legitimate value for getw to return, feof or terror should be used to detect end-of-file or error.

See also

Example

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

#define 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.