Re: [ROOT] a problem with using "strcat"

From: Stephen J. Gowdy (gowdy@SLAC.stanford.edu)
Date: Wed May 22 2002 - 04:41:12 MEST


What you're doing isn't good code. You are overwriting memory. Try using 
std::string instead.

On Tue, 21 May 2002 chen@beauty.physics.sc.edu wrote:

> Hi rooters,
> 
>        I have a problem using rootcint with the following macro :
> 
> *****************************************
> ..............
> char *var="name";
> char stringhf[] = var;
> char stringhg[] = var;
> char string1[] =">>";
> char string2[] = "hf";
> char string3[] = "hg";
> strcat(stringhf, string1);
> strcat(stringhf, string2);
> 
> ................
> 
> strcat(stringhg, string1);
> strcat(stringhg, string3);
> 
> cout << stringhf << endl;
> 
> cout << stringhf << endl;
> ......
> ***********************************************
>  The expected outputs are : name>>hf
>                             name>>hg
> 
> 
>  But,in fact, ther outputs are : name>>hf
>                                  name>>hf>>hg
> 
> 
> who know how to fix this problem?   Thanks!
> 
>                             
> 
> 
> 
> 
> 
> 

-- 
 /------------------------------------+-------------------------\
|Stephen J. Gowdy                     | SLAC, MailStop 34,       |
|http://www.slac.stanford.edu/~gowdy/ | 2575 Sand Hill Road,     |
|http://calendar.yahoo.com/gowdy      | Menlo Park CA 94025, USA |
|EMail: gowdy@slac.stanford.edu       | Tel: +1 650 926 3144     |
 \------------------------------------+-------------------------/



This archive was generated by hypermail 2b29 : Sat Jan 04 2003 - 23:50:53 MET