From mboxrd@z Thu Jan 1 00:00:00 1970 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: fee84,ca109b5548c034e4,start X-Google-Attributes: gidfee84,public X-Google-ArrivalTime: 1994-09-22 10:31:07 PST Path: bga.com!news.sprintlink.net!howland.reston.ans.net!math.ohio-state.edu!magnus.acs.ohio-state.edu!csn!decwrl!pa.dec.com!jac.zko.dec.com!hiyall.enet.dec.com!reagan From: reagan@hiyall.enet.dec.com (John R. Reagan) Newsgroups: comp.unix.osf.osf1 Subject: Re: Trailing blanks in packed character strings Date: 22 SEP 94 09:42:33 Organization: Digital Equipment Corporation Message-ID: <35s24t$t50@jac.zko.dec.com> References: <35pcqu$le8@senator-bedfellow.MIT.EDU> NNTP-Posting-Host: HIYALL In article <35pcqu$le8@senator-bedfellow.MIT.EDU>, clewley@wi.mit.edu (Suzanne Clewley) writes... >We are running into a problem in porting a program from VAX Pascal to >DEC Pascal under OSF/1 1.3. The name of a file is defined as a 30 >character packed text string. When read using ReadLn the text is >padded with blanks. A subsequent attempt to open the file fails, >because Pascal is looking for a file named "aa.aa > " (or there abouts), and not one named "aa.aa". How does one >truncate a packed string at the last non-blank character or >alternatively, read in a string of unknown characters without trailing >blanks? With DEC Pascal, you can use a STRING(n) or VARYING [n] OF CHAR instead of a PACKED ARRAY OF CHAR. Both STRING and VARYING have true run-time length so when you read into them, you don't get trailing blanks. Since they have a real length, the OPEN statement can determine the real end. PACKED ARRAYs OF CHAR must be blank-padded since they have no run-time length. There isn't a straightforward way of trimming trailing blanks other than reading backwards from the end. However, in your case, you have no embedded blanks in the filespec so you can chop off from the first blank. Here's an example: program foo(output); var p : packed array [1..32] of char; begin p := '12345'; writeln(substr(p,1,index(p,' ')-1)); end. --- John Reagan Application Compilers and Environments Digital Equipment Corporation reagan@hiyall.enet.dec.com Disclaimer: The opinions and statements expressed by me are not necessarily those of Digital Equipment Corporation. ---