Re: ustring to char*



On Wed, 2005-05-04 at 16:30 +0200, remco cats hccnet nl wrote:
> I also tried:
> termBox.insertLine(1, "QSTN: ", msgEntry.get_text());
> char* str;
> strcpy(str, msgEntry.get_text().c_str()); 
> rfcomm_write(mc3t_bt_dev, str);
> It will compile but when i want to use it it wil generate the following error:
> Program has been terminated receiving signal 11 (Segmentation fault)
> Press the Enter key to close this terminal ...

strcpy() doesn't allocate memory for the destination string, you have to
do that yourself before you copy anything to the str pointer. Or, if you
use a UNIX-like system, you can use strdup() which will allocate memory
for you. You'll have to free it yourself though.

-- 
Lars Luthman
PGP key:     http://www.d.kth.se/~d00-llu/pgp_key.php
Fingerprint: FCA7 C790 19B9 322D EB7A  E1B3 4371 4650 04C7 7E2E

Attachment: signature.asc
Description: This is a digitally signed message part



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]