home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #16 / NN_1992_16.iso / spool / comp / sys / amiga / programm / 11786 < prev    next >
Encoding:
Internet Message Format  |  1992-07-29  |  2.2 KB

  1. Path: sparky!uunet!elroy.jpl.nasa.gov!usc!wupost!psuvax1!psuvm!tew105
  2. Organization: Penn State University
  3. Date: Wed, 29 Jul 1992 12:51:58 EDT
  4. From: <TEW105@psuvm.psu.edu>
  5. Message-ID: <92211.125159TEW105@psuvm.psu.edu>
  6. Newsgroups: comp.sys.amiga.programmer
  7. Subject: Re: SAS/C 5.10b fopen(...,"w+") bug?
  8. Distribution: comp
  9. References:  <1992Jul26.190553.26493@wam.umd.edu>
  10. Lines: 34
  11.  
  12. In article <1992Jul26.190553.26493@wam.umd.edu>, walrus@wam.umd.edu (Udo K
  13. Schuermann) says:
  14. >I use SAS/C 5.10b under KS2.04 and am opening a file with a statement such
  15. >as the following:
  16. >
  17. >        struct FILE *myFile;
  18. >        myFile = fopen("t:test","w+");
  19. >
  20. >This clears out the file if it contains any information instead of preserving
  21. >existing information!  The documentation on page L72-L73 describes the use of
  22. >the "w+" mode as 1) creating the file if it doesn't exist yet, 2) preserving
  23. >existing contents (WHICH IT DOESN'T!), 3) providing r/w access to the file.
  24. >
  25. >The function behaves exactly as if I had not specified the "+" symbol in the
  26. >mode.  I have though.  I have I have I have!  :-/
  27. >
  28. It should behave exactly as if you opened it without the + except now you can
  29. preform reads and writes to the file (after a fseek).  It sounds like you want
  30. to use a different mode, either r or a.  Lets see, the problem with r is it
  31. won't open it if it doesn't exist, right?  So either use the a+ mode or check
  32. the r+ mode call and if it fails then open with a w+ mode.
  33.  
  34. One note about the a+ mode.  It should put you at the end of the file
  35. automatically, but you may want to do an fseek just to be sure.
  36. Also, when you are using a read/write mode, you need to preform an fseek
  37. between reads and writes (in other words you can't follow an fread with an
  38. fwrite.  You must put an fseek in between), at least when dealing with
  39. binary files.
  40.  
  41. +L8R+                                +What do you say to the child, whose god
  42. HonuS  internet: TEW105@psuvm.psu.edu|is in the TV?  And what do you say to the
  43. +---+  bitnet:   TEW105@psuvm        |man, who blames the world on TV? -Live
  44. Disclaimer: +-Look Ma, only 4 lines--+-I don't know, ask Oprah -me ----------+
  45.   The big wigs at PSU wish they could come up with opinions as good as mine!
  46.