brand@janus.Berkeley.EDU (Graham Brand) (09/27/90)
Dear All, Thanks to the 6 or so of you who replied. No one respondent in particular was completely correct; the solution turned out to be a combination of things. Most people mentioned the history of CP/M and ^Z and so suggested using the fseek(fp,-1L,SEEK_END) approach. A couple suggested using the "b" access_mode option as in fp=fopen("filename","rb+"). The solution that worked uses both of these. I must admit that I am not too sure why, but having spent more time on this simple problem than I had intended, I shan't worry about it too much. Before I lay the problem to rest, though, there is one peculiar aspect that I have not resolved. It is the fact that, before I added the fixes to the program, even if I ensured that the file did **NOT** have a ^Z eof termination when I started, my program would prepend a ^Z to any line of text that was added to the end of the file. The only file operations that were done in the program were fopen() and fprintf()? Where was the ^Z coming from and which of the changes, fseek(.,-1L,.) or fopen(.,"b"), cured it? Thanks for all your help, -Graham
mgphl@msa3b.UUCP (Michael Phillips) (09/29/90)
brand@janus.Berkeley.EDU (Graham Brand) writes: >... >any line of text that was added to the end of the file. The only file >operations that were done in the program were fopen() and fprintf()? >Where was the ^Z coming from and which of the changes, fseek(.,-1L,.) or >fopen(.,"b"), cured it? >Thanks for all your help, >-Graham Graham, Absolutely, positively, it was the fopen(.,"b") that cured your ^Z problem. Since ^Z is the "end-of-file" marker for _TEXT_ files, anytime a file is opened as _text_ ("t", the usual default), and the file is updated in some way, it should have a ^Z appended to the end. Now I think that the ^Z is basically useless, but it is the way DOS defines things so I live with it. Michael *-----------------------------------------------------------------------* D&B Software Atlnata, GA - "Constants aren't and Variables don't"