getw()                   Read an Integer from a Stream
 
 #include   <stdio.h>
 
 int        getw(stream);
 FILE       *stream;
 
    getw() gets the next integer from the specified input 'stream'. The
    file pointer is incremented to point to the next unread character.
 
    Returns:    The integer value read, if successful.  On error or
                end-of-file, EOF is returned.  Since EOF is a legitimate
                value for getw() to return, feof() or ferror() should be
                used to verify an end-of-file or error condition.
 
      Notes:    getw() does not assume any special alignment of items in
                the stream.
 
                getw() is provided primarily for compatibility with
                previous libraries.  Portability problems may occur with
                putw(), since the size of an 'int' and the ordering of
                bytes within an 'int' differ between systems.
 
  -------------------------------- Example ---------------------------------
 
    The following statements open an existing file, write integer values
    to it, reset the pointer to the beginning of the file, get the
    integer values, and print them out.
 
           #include <stdio.h>
           #include <stdlib.h>
 
           FILE *stream;
           long ptr;
           int i, x;
 
           main()
           {
               if ((stream = fopen("input.dat","w+"))!= NULL) {
                   for (x = 0; x <=  10; x++)
                       putw(x,stream);
                   fseek(stream,0L,SEEK_SET);
                   while (!feof(stream)) {
                         i = getw(stream);
                         printf("%d ",i);
                         if (ferror(stream)) {
                            printf("error on input");
                            clearerr(stream);
                         }
                   }
                   fclose(stream);
               }
           }

Seealso:



This page last updated on Fri Nov 30 10:48:32 MSK 2001
Copyright © 1992-2001, Vitaly Filatov, Moscow, Russia
Webmaster