Lots of things are wrong, taking it a line at a time:

char            s[1];

Strings are null terminated (char, char, char, 0).  Allocating one byte
leaves only room for the terminator, none for characters.

CharPtr textOut, text1=s, text2=s;

CharPtr is a 'Char *' - ie, the _address_ of a string, not storage for the
string itself, your textOut does not allocate space for the constructed
string.  Your assignment of text1 and text2 to s has no real effect, since
you reassign both in the next two lines (see below).

text1="a";
text2="b";

Each of these two lines creates a string in memory (2 bytes each, the
character and a null terminator) and sets each pointer to the address of the
allocated string.

textOut=StrCat(textIn, textTemp);

First, textIn and textTemp don't exist, second, StrCat appends src (second
argument) to dst (first argument), the return value can be ignored - BUT,
dst must be associated with enough allocated space to hold the combined
strings plus a null terminator.

Try this instead:

char mystr[40];  //Or whatever the maximum string length -1 will be

StrCopy(mystr, "a");
// mystr now contains "a",0
StrCat(mystr, "b");
// mystr now contains "ab",0
StrCat(mystr, "c");
// mystr no contains "abc",0

/*
   viewed another way:

   mystr[0] == 'a'
   mystr[1] == 'b'
   mystr[2] == 'c'
   mystr[3] == 0
*/

Good Luck,
-jjf

-----Original Message-----
From: Farzin Ashraghi [mailto:[EMAIL PROTECTED]]
Sent: Friday, July 07, 2000 3:10 PM
To: Palm Developer Forum
Subject: StrCat


Hi!

I'm having problems using StrCat. I want to obtain texOut = "ab". 
Could you tell me please, what is wrong with this?

char            s[1];
CharPtr textOut, text1=s, text2=s;
text1="a";
text2="b";
textOut=StrCat(textIn, textTemp);

Thank you!
Farzin

-- 
For information on using the Palm Developer Forums, or to unsubscribe,
please see http://www.palmos.com/dev/tech/support/forums/

-- 
For information on using the Palm Developer Forums, or to unsubscribe, please see 
http://www.palmos.com/dev/tech/support/forums/

Reply via email to