home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 5 / 05.iso / a / a079 / 1.img / FPDG.LZH / VOL2NUM0 / FSEEK / FSEEK.BAK < prev    next >
Encoding:
Text File  |  1992-07-26  |  2.7 KB  |  62 lines

  1. ***************************************************************
  2. *     * 07/26/92            DESKACC.PRG               9:31:22 *
  3. ***************************************************************
  4. *     *                                                       *
  5. *     * Description:                                          *
  6. *     *   This program illustrates how to use the FSEEK       *
  7. *     *   low-level I/O function                              *
  8. ***************************************************************
  9. SET TALK OFF
  10. CLOSE ALL    && Close all files, etc. including low-level files
  11. STORE 0 TO BEGIN
  12. STORE 1 TO CURRENT
  13. STORE 2 TO END
  14. ***************************************************************
  15.  
  16. ON ERROR DO FileError        && Set error trap
  17. Handle = FOPEN("FOO.TXT",2)  && Open file for read/write       
  18. IF Handle < 0
  19.     DO FileError
  20.     RETURN
  21. ENDIF    
  22. NewLoc = FSEEK(Handle, 0, END)      && Move to end of file
  23. DO ShowAnswer WITH NewLoc, "Move to end of file" 
  24. NewLoc = FSEEK(Handle, 0, BEGIN)    && Move to beginning of file 
  25.                                     &&   (rewind)
  26. DO ShowAnswer WITH NewLoc, "Move to beginning of file" 
  27. NewLoc = FSEEK(Handle, 50, BEGIN)   && Move to before 51th byte
  28. DO ShowAnswer WITH NewLoc, "Move to 51th byte" 
  29. NewLoc = FSEEK(Handle, 5, CURRENT)  && Move 5 characters forward
  30.                                     &&   from current position
  31. DO ShowAnswer WITH NewLoc, "Move 5 characters forward" 
  32. NewLoc = FSEEK(Handle, -15, CURRENT)  && Move 15 characters
  33.                                       &&   backward from 
  34.                                       &&   current position
  35. DO ShowAnswer WITH NewLoc, "Move 15 characters backwards" 
  36. NewLoc = FSEEK(Handle, 0, CURRENT)  && Determine current position
  37. DO ShowAnswer WITH NewLoc, "Determine current position" 
  38. NewLoc = FSEEK(Handle, 0)           && Move to beginning of file
  39. DO ShowAnswer WITH NewLoc, "Move to beginning of file" 
  40. ***********************************************************
  41. * Now change all occurrences of "cat" with "dog" in file
  42. DO WHILE .NOT. FEOF(Handle)
  43.      Position = FSEEK(Handle, 0, CURRENT)   && Save position
  44.      String = FGETS(Handle)
  45.      Position = FSEEK(Handle, Position, BEGIN )   && Move back
  46.      String = STRTRAN(String, "cat", "dog", 1, 99)
  47.      = FPUTS(Handle, String)
  48.      ENDDO
  49. ENDIF     
  50. ON ERROR
  51. = FCLOSE( Handle )
  52. ******************************************************************
  53. PROCEDURE FileError
  54. WAIT "File I/O Error #"+STR(FERROR()) WINDOW
  55. RETURN     
  56. ******************************************************************
  57. PROCEDURE ShowAnswer
  58. PARAMETER Position, Message
  59. WAIT Message + "   New file position: " ;
  60.     +LTRIM(STR(Position)) WINDOW
  61. RETURN
  62.