home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #20 / NN_1992_20.iso / spool / comp / os / msdos / programm / 9317 < prev    next >
Encoding:
Internet Message Format  |  1992-09-12  |  1.8 KB

  1. Xref: sparky comp.os.msdos.programmer:9317 comp.lang.c:13602
  2. Newsgroups: comp.os.msdos.programmer,comp.lang.c
  3. Path: sparky!uunet!haven.umd.edu!darwin.sura.net!eng.ufl.edu!manta!zzang
  4. From: zzang@stat.ufl.edu (Zhuo Zang)
  5. Subject: Re: BC++2.0 lseek problem(ALSO:lseek() question)
  6. Message-ID: <1992Sep13.011428.25100@eng.ufl.edu>
  7. Originator: zzang@manta
  8. Sender: news@eng.ufl.edu (Usenet Diskhog System)
  9. Organization: University of Florida
  10. References: <1992Sep12.235241.23213@eng.ufl.edu>
  11. Distribution: usa
  12. Date: Sun, 13 Sep 92 01:14:28 GMT
  13. Lines: 57
  14.  
  15. Hello,
  16. I have a typo in the code, so there is no
  17. question in comp.lang.c .
  18. the bug in BC++2.0 is still unsolved.
  19.  
  20. In article <1992Sep12.235241.23213@eng.ufl.edu> zzang@stat.ufl.edu (Zhuo Zang) writes:
  21. >Hello,
  22. >the following program using lseek will
  23. >give different results in BC++2.0 than
  24. >that of in UNIX.
  25. >the BC++2.0 will print the last character twice.
  26. >
  27. >------- foo.c ----------
  28. >/* use bcc -DMSDOS foo.c to compile in BC++i
  29. >   use cc foo.c to compile under UNIX */
  30. >#include <stdio.h>
  31. >#include <fcntl.h>
  32. >#ifdef MSDOS 
  33. >#include <io.h>
  34. >#else
  35. >#include <sys/file.h>
  36. >#endif
  37. >
  38. >char *sp, buf[BUFSIZ];
  39. >int fd;
  40. >int get(int fd, long pos, char *buf, int n);
  41. >
  42. >int main()
  43. >{
  44. >  sp = buf;
  45. >  fd = open("foo.c", O_RDONLY, 0);
  46. >  get(fd, 3, sp, 20);
  47. >/* I have question here, where does the sp point now? 
  48. >   please notice the assignment sp = '\0', and the output
  49. there is a typo here, should be *sp = '\0', sorry.
  50. no question! :-)
  51. >   of the program */
  52. >  puts(sp);
  53. >  sp = '\0';
  54. >  puts(buf);
  55. >  return 0;
  56. >}
  57. >
  58. >int get(int fd, long pos, char *buf, int n)
  59. >{
  60. >    if (lseek(fd, pos, 0) >= 0)
  61. >    return read(fd, buf, n);
  62. >    else
  63. >    return -1;
  64. >}
  65. >
  66.  
  67.  
  68. -- 
  69. Zhuo Zang[~{j0WA~}]
  70. Department of Statistics
  71. University of Florida            Email: zzang@stat.ufl.edu
  72.