🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

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

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

#14205
From: Rodolfo Frino
Date: Wed, 20 Aug 2003 22:22
63 lines
2202 bytes
These are some posibilities

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


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


Example3:
 AnsiString Buffer = "Your string 3";
 Caption = Buffer;



Example4:
 AnsiString Buffer[] = {"Your string 1", "Your string 2", "Your string 3"};

 String S = "";
 for (int i=0; i<ARRAYSIZE(Buffer); ++i)
 {
     S += Buffer[i] + " ";
 }
 Caption = S;


Example5:
 char* Buffer[] = {"Your string 1", "Your string 2", "Your string 3"};

 String S = "";
 for (int i=0; i<ARRAYSIZE(Buffer); ++i)
 {
     S += String(Buffer[i]) + " ";
 }
 Caption = S;


Notice that you assign a value to the buffer like that
 char* Buffer = "Your string 1";

only at declaration.

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

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

Rodolfo


"Richard Yu" <richard@colorselector.com> wrote in message
news:3f43e3f5$1@newsgroups.borland.com...
> I have  a text string , like "a string", want to assign into a buffer,
> defined as char* buffer, how to do that ?
> thank.
>
>
Technical Details
Message-ID: <3f43f466@newsgroups.borland.com>
Path: arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!sn-xit-02!sn-xit-06!sn-xit-01!sn-xit-08!supernews.com!newsfeed.wirehub.nl!news.kweb.on.ca!KWeb!newsgroups.borland.com!not-for-mail
References: <3f43e3f5$1@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 15:28:02 PST
From: "Rodolfo Frino" <rodolfofrino@yahoo.com>
Newsgroups: borland.public.cppbuilder.nativeapi
References: <3f43e3f5$1@newsgroups.borland.com>
Subject: Re: How to assign text to a char *buffer ?
Date: Thu, 21 Aug 2003 08:22:00 +1000
Lines: 65
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.1165
NNTP-Posting-Host: 203.206.27.108
Message-ID: <3f43f466@newsgroups.borland.com>
X-Trace: newsgroups.borland.com 1061418086 203.206.27.108 (20 Aug 2003 15:21:26 -0700)
Path: arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!sn-xit-02!sn-xit-06!sn-xit-01!sn-xit-08!supernews.com!newsfeed.wirehub.nl!news.kweb.on.ca!KWeb!newsgroups.borland.com!not-for-mail