home *** CD-ROM | disk | FTP | other *** search
/ Programmer 7500 / MAX_PROGRAMMERS.iso / INFO / C / R_LA4_02.ZIP / SYSREAD2.C < prev    next >
Encoding:
C/C++ Source or Header  |  1988-01-13  |  887 b   |  30 lines

  1. /* SYSREAD2.C - From page 463 of "Microsoft C Programming for   */
  2. /* the IBM" by Robert Lafore. This program reads and displays   */
  3. /* a file using system I/O.  Usage: A>sysread2 filename.ext     */
  4. /* This program differs from SYSREAD.C only in that it uses     */
  5. /* the perror() function.                                       */
  6. /****************************************************************/
  7.  
  8. #include "fcntl.h"
  9. #define BUFFSIZE 512
  10. char buff[BUFFSIZE];
  11.  
  12. main(argc, argv)
  13. int argc;
  14. char *argv[];
  15. {
  16. int inhandle, bytes, j;
  17.  
  18.    if(argc != 2) {
  19.       printf("\nFormat: A>sysread2 filename.ext");
  20.       exit();
  21.    }
  22.    if((inhandle = open(argv[1], O_RDONLY | O_BINARY)) < 0)
  23.       perror("\nCan't open input file");
  24.    while((bytes = read(inhandle, buff, BUFFSIZE)) > 0)
  25.       for(j = 0; j < bytes; j++)
  26.          putch(buff[j]);
  27.    close(inhandle);
  28. }
  29.  
  30.