Retro video games delivered to your door every month!
Click above to get retro games delivered to your door ever month!
X-Hacker.org- Microsoft C 6.0 - <b>getw() read an integer from a stream</b> http://www.X-Hacker.org [<<Previous Entry] [^^Up^^] [Next Entry>>] [Menu] [About The Guide]
 getw()                  Read an Integer from a Stream

 #include   <stdio.h>

 int        getw(stream);
 FILE       *stream;                     Pointer to FILE structure

    getw() gets the next integer from the specified input 'stream'. The
    file pointer is incremented to point to the next unread character.

    Returns:    On success, returns the integer value read.  On error or
                end-of-file, returns EOF, which is a legitimate return
                value.  feof() or ferror() should be used to verify which
                of these conditions occurred.

      Notes:    No special alignment of stream items is assumed by
                getw().

                getw() exists mainly to provide compatibility with
                existing libraries but, because there are differences
                among systems in the size of an 'int' and the ordering of
                bytes within 'int', using getw() may cause problems in
                portability.

 Portability:   Not supported by ANSI standard.

   -------------------------------- 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);
               }
           }




See Also: putw() feof() ferror()

Online resources provided by: http://www.X-Hacker.org --- NG 2 HTML conversion by Dave Pearson