home *** CD-ROM | disk | FTP | other *** search
/ DP Tool Club 17 / CD_ASCQ_17_101194.iso / dos / prg / sphinx / examples / other / open.c__ < prev    next >
Encoding:
Text File  |  1993-04-30  |  1.0 KB  |  33 lines

  1. /*
  2.     SPHINX C-- example program
  3.     Name:  OPEN.C--
  4.     Description:  This file demonstrates some of the C-- file commands.
  5. */
  6.  
  7. ?include "FILE.H--"
  8. ?include "WRITE.H--"
  9.  
  10. word filehandle;     /* file handle holder */
  11.  
  12. ?define BYTESTOREAD 136
  13. byte buffer[BYTESTOREAD+1]; /* buffer to read part of file into */
  14.  
  15. main ()
  16. {filehandle = open("OPEN.C--",F_READ);  /* open file for reading */
  17. IF(filehandle == 0)                    /* if file did not open */
  18.     WRITESTR("Unable to open file 'OPEN.C--'.\n"); /* display error message */
  19. ELSE{WRITESTR("File opened O.K.\n");
  20.     IF( read(filehandle,#buffer,BYTESTOREAD) != BYTESTOREAD )
  21.         WRITESTR("Error Reading from file.\n"); 
  22.     ELSE{WRITESTR("File read O.K., bytes read into buffer:\n");
  23.         buffer[BYTESTOREAD] = 0;  // put a string terminator at the end
  24.         WRITESTR(#buffer);
  25.         WRITELN();
  26.         }
  27.     IF( close(filehandle) == 0 )  /* close the file */
  28.         WRITESTR("File closed O.K.\n");
  29.     ELSE WRITESTR("Error closing file.\n");
  30.     }
  31. }
  32.  
  33. /* end of OPEN.C-- */