Path: utzoo!attcan!telly!druid!darcy From: darcy@druid.uucp (D'Arcy J.M. Cain) Newsgroups: comp.lang.c Subject: Re: append mode "a" query Message-ID: <1990Feb16.180007.1166@druid.uucp> Date: 16 Feb 90 18:00:07 GMT References: <5003.25dabd8f@uwovax.uwo.ca> Reply-To: darcy@druid.UUCP (D'Arcy J.M. Cain) Organization: D'Arcy Cain Consulting, West Hill, Ontario Lines: 42 In article <5003.25dabd8f@uwovax.uwo.ca> chet@uwovax.uwo.ca writes: > >(2) The EOF (^Z, dec 26) was introduced by an assembly language editor >that I sometimes use. When I used only MicroEMACS, program B ran >without problem on Turbo C and Small-C. Whenever I used the other >editor, the ^Z crept in (I used a third, binary, editor to confirm >these facts). > >(3) For Turbo C, a simple fix was to change the mode from "a" (which by >default is "at") to "r+" and then use lseek(fp, -1, 2). This position >the file pointer just before the EOF. Note, however, that it should not >be necessary to do this! > Why not? If you have an editor that thinks it is running on CP/M and must add a ^Z to the end of the file then why wouldn't an append happen after the last character in a file. Do you think there is something special about ^Z that DOS or fopen should recognize? After all ^Z doesn't even make any sense as an end of file. It is a SUB (substitute) character in ASCII. I would think the following would make at least as much sense as an end of file marker if one was needed: ^C ETX End of text ^D EOT End of transmission ^W ETB End of transmission block ^Y EM End of medium ^\ FS File separator So why not have append append from the ^D for instance. Nope. The proper thing for append to do is go to the end of the physical file and the programmer must back up if there are characters in the file that don't belong there. Maybe you should write a utility that searches for ^Z and resizes the file to the character before it. Then you have a standard file which append works properly on. -- D'Arcy J.M. Cain (darcy@druid) | Thank goodness we don't get all D'Arcy Cain Consulting | the government we pay for. West Hill, Ontario, Canada | (416) 281-6094 |