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>putw() write an integer to stream</b> http://www.X-Hacker.org [<<Previous Entry] [^^Up^^] [Next Entry>>] [Menu] [About The Guide]
 putw()                  Write an Integer to Stream

 #include   <stdio.h>

 int        putw(binint,stream);
 int        binint;                      Binary integer to be output
 FILE       *stream;                     Pointer to file structure

    putw() outputs the integer 'binint' to the current position of
    'stream'.  putw() does not expect special alignment of items in the
    stream, and does not cause special alignment in the file.

    Returns:    The value written. On error, EOF is returned.  EOF is a
                legitimate integer value, however, so ferror() should be
                used to verify an error.

      Notes:    putw() exists to provide compatibility with previous
                libraries.  Because the size of an 'int' and the ordering
                of bytes within an 'int' are different in different
                systems, portability problems may occur with putw().

 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: getw()

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