Board index » delphi » Null-terminated string

Null-terminated string

I've tried to read a null-terminated string with the readln command
but the compiler sais that it can't read that type of variables.
How do I read null-terminated-strings???

PS I use BP7.0 and $X+

Regards Henrik

 

Re:Null-terminated string


kjolh...@algonet.se wrote in article <32f4c6a1.4388...@news.algonet.se>...

Quote
> I've tried to read a null-terminated string with the readln command
> but the compiler sais that it can't read that type of variables.
> How do I read null-terminated-strings???

> PS I use BP7.0 and $X+

> Regards Henrik

        You have to read the string into a conventional
        string, then assign it to your null terminated string
        with StrPCopy.

        e.g.

        var s:string;
             p:array[0..255]of char;
        Readln(S);
        strpcopy(P,S);

--
Hilton Evans
***********************************************************
The two most important things in life are personal
health and time ... H.Evans 1995
**********************************************************
Chempen+ Chemical Structure Drawing
Software for Windows
http://www.ici.net/cust_pages/hfevans/chempen.htm

Re:Null-terminated string


Quote
In article <32f4c6a1.4388...@news.algonet.se>, kjolh...@algonet.se wrote::
>I've tried to read a null-terminated string with the readln command
>but the compiler sais that it can't read that type of variables.
>How do I read null-terminated-strings???

>PS I use BP7.0 and $X+

var a:array[0..size] of char;
begin
   readln(a);
   writeln(a)
end;

You may not read strings using a variable of type PCar because the RTL
wouldn't know how much memory is available. In this case a maximum of
size-1 chars will be read and a #0 will be appended. Same procedure for
regular text files.

Regards
wo

Other Threads