home *** CD-ROM | disk | FTP | other *** search
/ Microsoft Programmer's Library 1.3 / Microsoft-Programers-Library-v1.3.iso / sampcode / alde_c / misc / lib / dlibssrc / getw.c < prev    next >
Encoding:
C/C++ Source or Header  |  1987-07-17  |  535 b   |  34 lines

  1. #include <stdio.h>
  2.  
  3. int getw(fp)
  4. FILE *fp;
  5. /*
  6.  *    Get a 2-byte value from the stream <fp>.  The high-order byte is
  7.  *    read first.
  8.  */
  9. {
  10.     register int n, c;
  11.  
  12.     if((c = fgetc(fp)) == EOF)
  13.         return(EOF);
  14.     n = (c << 8);
  15.     if((c = fgetc(fp)) == EOF)
  16.         return(EOF);
  17.     n |= (c & 0xFF);
  18. }
  19.  
  20. int putw(n, fp)
  21. register int n;
  22. FILE *fp;
  23. /*
  24.  *    Put the 2-byte value <n> to the stream <fp>.  The high-order byte
  25.  *    is written first.
  26.  */
  27. {
  28.     register int m;
  29.  
  30.     m = (n >> 8);
  31.     fputc((m & 0xFF), fp);
  32.     fputc((n & 0xFF), fp);
  33. }
  34.