home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #20 / NN_1992_20.iso / spool / comp / os / msdos / programm / 9315 < prev    next >
Encoding:
Text File  |  1992-09-12  |  1.4 KB  |  61 lines

  1. Xref: sparky comp.os.msdos.programmer:9315 comp.lang.c:13601
  2. Newsgroups: comp.os.msdos.programmer,comp.lang.c
  3. Path: sparky!uunet!zaphod.mps.ohio-state.edu!sdd.hp.com!uakari.primate.wisc.edu!eng.ufl.edu!manta!zzang
  4. From: zzang@stat.ufl.edu (Zhuo Zang)
  5. Subject: BC++2.0 lseek problem(ALSO:lseek() question)
  6. Message-ID: <1992Sep12.235241.23213@eng.ufl.edu>
  7. Originator: zzang@manta
  8. Sender: news@eng.ufl.edu (Usenet Diskhog System)
  9. Organization: University of Florida
  10. Distribution: usa
  11. Date: Sat, 12 Sep 92 23:52:41 GMT
  12. Lines: 47
  13.  
  14. Hello,
  15. the following program using lseek will
  16. give different results in BC++2.0 than
  17. that of in UNIX.
  18. the BC++2.0 will print the last character twice.
  19.  
  20. ------- foo.c ----------
  21. /* use bcc -DMSDOS foo.c to compile in BC++i
  22.    use cc foo.c to compile under UNIX */
  23. #include <stdio.h>
  24. #include <fcntl.h>
  25. #ifdef MSDOS 
  26. #include <io.h>
  27. #else
  28. #include <sys/file.h>
  29. #endif
  30.  
  31. char *sp, buf[BUFSIZ];
  32. int fd;
  33. int get(int fd, long pos, char *buf, int n);
  34.  
  35. int main()
  36. {
  37.   sp = buf;
  38.   fd = open("foo.c", O_RDONLY, 0);
  39.   get(fd, 3, sp, 20);
  40. /* I have question here, where does the sp point now? 
  41.    please notice the assignment sp = '\0', and the output
  42.    of the program */
  43.   puts(sp);
  44.   sp = '\0';
  45.   puts(buf);
  46.   return 0;
  47. }
  48.  
  49. int get(int fd, long pos, char *buf, int n)
  50. {
  51.     if (lseek(fd, pos, 0) >= 0)
  52.     return read(fd, buf, n);
  53.     else
  54.     return -1;
  55. }
  56.  
  57. -- 
  58. Zhuo Zang[~{j0WA~}]
  59. Department of Statistics
  60. University of Florida            Email: zzang@stat.ufl.edu
  61.