🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: borland.public.cppbuilder.nativeapi
Article #14209

Re: How to assign text to a char *buffer ?

#14209
From: Remy Lebeau (TeamB)
Date: Wed, 20 Aug 2003 22:53
42 lines
2183 bytes
"Rodolfo Frino" <rodolfofrino@yahoo.com> wrote in message
news:3f43f466@newsgroups.borland.com...

> Example1:
>  char* Buffer = "Your string 1";
>  Caption = String(Buffer);

There's no need to cast, AnsiString has a char* constructor and a char*
assignment operator.  You can assign the char* to the Caption directly:

    char* Buffer = "Your string 1";
    Caption = Buffer;

> Example2:
>  char Buffer[] = "Your string 2";
>  Caption = String(Buffer);

Same here.

> If you declare a buffer without initializing it, such as
> char* Buffer;
>
> You cannot use the assignment operator to initialize it:
> Buffer = "Your string 1";            // Error

Of course you can.  You have declared a char* pointer and you are assigning
it a hard-coded char* that resides in static memory.  That is a perfectly
valid operation, it is not an error.

> You can use strcpy() or strncpy() later to initialize it

Only if you have allocated the memory for the buffer first.


Gambit


---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.510 / Virus Database: 307 - Release Date: 8/14/03
Technical Details
Message-ID: <3f440875$1@newsgroups.borland.com>
Path: arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!sn-xit-02!sn-xit-06!sn-xit-08!supernews.com!priapus.visi.com!news-out.visi.com!petbe.visi.com!newsfeed.wirehub.nl!news.kweb.on.ca!KWeb!newsgroups.borland.com!not-for-mail
References: <3f43e3f5$1@newsgroups.borland.com> <3f43f466@newsgroups.borland.com>

Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: 10cc67,80747dfc78851287
X-Google-Attributes: gid10cc67,public
X-Google-ArrivalTime: 2003-08-20 16:57:03 PST
From: "Remy Lebeau \(TeamB\)" <gambit47@yahoo.com>
Newsgroups: borland.public.cppbuilder.nativeapi
References: <3f43e3f5$1@newsgroups.borland.com> <3f43f466@newsgroups.borland.com>
Subject: Re: How to assign text to a char *buffer ?
Date: Wed, 20 Aug 2003 15:53:55 -0700
Lines: 44
X-Priority: 3
X-MSMail-Priority: Normal
X-Newsreader: Microsoft Outlook Express 6.00.2800.1158
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1106
NNTP-Posting-Host: 207.175.226.26
Message-ID: <3f440875$1@newsgroups.borland.com>
X-Trace: newsgroups.borland.com 1061423221 207.175.226.26 (20 Aug 2003 16:47:01 -0700)
Path: arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!sn-xit-02!sn-xit-06!sn-xit-08!supernews.com!priapus.visi.com!news-out.visi.com!petbe.visi.com!newsfeed.wirehub.nl!news.kweb.on.ca!KWeb!newsgroups.borland.com!not-for-mail