Usenet comp.unix.osf.osf1 (1992-2004)
 help / color / mirror / Atom feed
* Re: Trailing blanks in packed character strings
       [not found] <35pcqu$le8@senator-bedfellow.MIT.EDU>
@ 1994-09-22 13:42 ` John R. Reagan
  0 siblings, 0 replies; only message in thread
From: John R. Reagan @ 1994-09-22 13:42 UTC (permalink / raw)



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.
---


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~1994-09-22 13:42 UTC | newest]

Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
     [not found] <35pcqu$le8@senator-bedfellow.MIT.EDU>
1994-09-22 13:42 ` Trailing blanks in packed character strings John R. Reagan

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox