Re: [ROOT] String Array

From: Patois Yannick (patois@ganil.fr)
Date: Wed Oct 04 2000 - 14:28:14 MEST


On Wed, 4 Oct 2000, Roland Bramm wrote:

> Char_t *Names[20][80];
> 
> Names[1][] = "The Filled Text"; // Sometimes this is filled more than 

I'm not sure about the meaning of such a line.
Names is a ***char,
so each Names[i][j] is a *char.
I would understand Names[i][j] = "const string";
And then :
cout << Names[i][j];

But here, for me you're filling char* cells with chars.

If I follow you, I would have wrote either :

 Char_t Names[20][80]; // allocation of a static array of chars 
 for (int i=0;i<20;i++)
   sprintf(Names[i],"The Filled Text %d",i);

 strcpy(Name[1],"ANOTHER TEXT");
	
 for(int j = 0; j<20;j++){
       cout << Names[j]  << endl;
 }

Or :

 Char_t *Names[20]; // allocation of an array of char pointers   
 for (int i=0;i<20;i++)
 {
   char *prv=new char[80];
   sprintf(prv,"The Filled Text %d",i);
   Names[i]=prv;
 }

 delete Names[1];
 Names[1]="ANOTHER TEXT";

 for(int j = 0; j<20;j++){
       cout << Names[j]  << endl;
 }


Hope it helps,

	Yannick



This archive was generated by hypermail 2b29 : Tue Jan 02 2001 - 11:50:34 MET