cvs.gedasymbols.org/archives/browse.cgi   search  
Mail Archives: djgpp/1999/08/12/22:28:45

From: Weiqi Gao <weiqigao AT a DOT crl DOT com>
Newsgroups: comp.os.msdos.djgpp
Subject: Re: Catenation (spelled right?) of strings
Date: Thu, 12 Aug 1999 20:44:48 -0500
Organization: CRL Network Services
Lines: 33
Message-ID: <37B37890.2C249FED@a.crl.com>
References: <37B36D0D DOT 7F00 AT lords DOT com>
NNTP-Posting-Host: a116011.stl1.as.crl.com
Mime-Version: 1.0
X-Mailer: Mozilla 4.6 [en] (X11; I; Linux 2.0.36 i586)
X-Accept-Language: en
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp
Reply-To: djgpp AT delorie DOT com

"Robinson S." wrote:
> 
> Is it possible to group a bunch of strings into an array of char:
> 
> I tried this:
> char THE_STRING [255];
> THE_STRING = "GOATS " + "MAKE " + "GOOD " + "PETS!";
> 
> My compiler (DGJPP gccw32.exe) says: "invalid operands to binary +"
> 
> How do I join those strings?

The correct thing to do is:
  char *theString = "Goats " "make " "good " "pets!";

Your code has two problems:

1.  The plus ('+') operator cannot be used on C-style strings.  The
concatenate two literal strings, you simply put them side by side.  Not
that this worked only for literal strings, and wouldn't work for
variables.

2.  char THE_STRING[255]; declares THE_STRING as an array.  Once an
array is declared, you cannot change it.  The line "THE_STRING = ..." is
seen by the compiler as an attempt to change THE_STRING, and will not
compile.  Other attempts to change THE_STRING itself like THE_STRING++
will also cause a compile time error.  The individual elements of the
array can be changed, though, e.g., THE_STRING[0] = 'G'; THE_STRING[1] =
'O'; are legal.

-- 
Weiqi Gao
weiqigao AT a DOT crl DOT com

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019