Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!mnetor!seismo!columbia!rutgers!husc6!cca!g-rh From: g-rh@cca.CCA.COM (Richard Harter) Newsgroups: comp.lang.c Subject: Re: C ON VMS Message-ID: <16299@cca.CCA.COM> Date: Sun, 31-May-87 14:41:06 EDT Article-I.D.: cca.16299 Posted: Sun May 31 14:41:06 1987 Date-Received: Tue, 2-Jun-87 02:10:59 EDT References: <7614@brl-adm.ARPA> Reply-To: g-rh@CCA.CCA.COM.UUCP (Richard Harter) Organization: Computer Corp. of America, Cambridge, MA Lines: 49 Summary: RTFM (but it aint easy) In article <7614@brl-adm.ARPA> ADLER1%BRANDEIS.BITNET@wiscvm.wisc.EDU writes: >I am having a problem with C on VAX/VMS which I could perhaps solve if the >DEC documentation were reliable, which it is not. > Whoa, this is a bunch of horse puckey. The manual is reliable and pretty complete. Your snide remarks about DEC documentation are out of line. The VMS C manual is obscure in places, poorly organized (in my opinion), and very confusing on this matter to someone who is used to the UNIX treatment of files. However the information is there, and you don't have to read the RMS manual. >The problem has to do with using C to handle files. To be concrete, consider >a program which prompts the user for a character, a string, a sourcefile >name and a target file name and then copies the source file one character at >a time to the target file except that it replaces every occurrence of the >given ccharacter by the given string. This is a pretty simple program to >write. > Fundamentally the problem is this: VMS supports a number of different file formats, block sizes, etc. In the creat, fopen, etc routines you can optionally add record descriptor qualifiers as additional arguments. If you don't you get defaults, and they are UNIX type defualts which are not the same as VMS defaults. If you open files and read and write from and to the files and you use the wrong descriptors you get funny results. You can even figure out what they will be, if you RTFM. What you probably want is: fptr=fopen(fn,"w","rfm=var","rat=cr");/* Create file */ or fnum = creat(fn,0,"rfm=var","rat=cr");/* Create output file */ fptr = fdopen(fnum,"w"); /* Get file struct ptr */ where fptr is FILE * and fnum is int, to be used in conjuction with fprintf. These will write files in the standard VMS format. Don't use open/read/write unless you know exactly what you're doing. In the above, "rfm=var" says that the file is a variable length file (double count byte at the beginning.) The 'rat=cr" says that the record terminator is a carriage return, rather than a line feed. This is what the editor expects. What has happened is that your choice of formats is inconsistent. What the manual should have (and doesn't as far as I can recall) is an explicit statement as to what to do for ordinary file read/write (i.e. you want to read a standard format file and write same.) However I don't have a copy at hand, so maybe it is buried in there somewhere. -- Richard Harter, SMDS Inc. [Disclaimers not permitted by company policy.]