[Q]Pascal packed arrary of char and varying of char



Hi Group,

I am trying to update a pascal program, with very little pascal
experience.

The code is full of string of two types - packed array of char and
varying of char.

Most places it uses packed array of char and then copies this to
varying of char.
In the routines that have the varying of char I am trying to work out
the length of the string to display nicely.

In the following code I am trying to obtain the the length the varying
of char string, that has been 'copied' from packed array of char.
However I always get 50.

How do I work out the length of the varying of char string? (I thinks
22 is the correct answer)

Thanks

Stuart

[inherit ('sys$library:starlet', 'sys$library:pascal$lib_routines')]
program test (input, output);

type
mystring = varying [256] of char;

var
namepacked : packed array [1..50] of char;
namevary : mystring;

begin

namepacked := 'the cat sat on the mat';
namevary := namepacked;

writeln ('Length = ', length(namevary), ' .Length
=',namevary.length);
end.

.



Relevant Pages

  • Re: What my life is really like....
    ... > is variable length and a packed array of char really ... IIRC, original Pascal only had string literals, and these could be ... treated as packed array of char. ...
    (comp.lang.pascal.delphi.misc)
  • [PATCH 09/21] perf: rewire generic library stuff, p5
    ... +int eprintf(int level, const char *fmt, ...) ... * Helper function for splitting a string into an argv-like array. ... +static int count_argc(const char *str) ...
    (Linux-Kernel)
  • Re: How to add thousand separators
    ... First, this code is obsolete as written, because char is a dead data type and should not ... Note that both of these should be stored as string resources since they might need to be ... 18 digits for any reason. ... you have made a VERY SERIOUS DESIGN ERROR. ...
    (microsoft.public.vc.mfc)
  • Re: Returning a character buffer from a DLL
    ... I need to return a string buffer from the DLL in a RunQuery function. ... I find it odd that you are using the obsolete 'char *' data type here. ... want to use a string pointer of any type here! ...
    (microsoft.public.vc.mfc)
  • Re: what is the best way of passing floats into a string
    ... I do not null-terminate as snprintf takes care of this (according to ... But the easiest way to determine the size needed to format a number, ... int length_of_representation(double n,const char* format){ ... I get a nice result of -10.000000 in my char * string. ...
    (comp.unix.programmer)