Re: [ROOT] Iitialization of string characters

From: Valeri Fine (Faine) (fine@bnl.gov)
Date: Mon Sep 11 2000 - 18:14:57 MEST


I did it under Windows and it works. However the original message
did not say what was wrong really.


By the way, it is better to let the compiler to define the array size as follows:

  char* HisXTit[] = {  }
  const int MaxHistos = sizeof(HisXTit)/sizeof(char *);

namely:

{
  gROOT->Reset();


  // Initialize array of pointers
  char* HisXTit[] = {
    "xCal",  "yCal", "yCal",
    "xHES",  "yHES", "yHES",
    "xCal",  "yCal", "yCal",
    "rCal",  "rCal", "rCal",
    "rHES",  "rHES", "rHES",
    "rCal",  "rCal", "rCal",
    "zCal",  "xCal", "xCal",
    "yCal",  "yCal", "zCal"
  };

  int i;

  const int MaxHistos = sizeof(HisXTit)/sizeof(char *);
  printf(" size = %d\n",MaxHistos);
  for(i=0;i<MaxHistos;i++){
    printf("%s\n",HisXTit[i]);
  }
}

  Valery
==========



----- Original Message -----
From: Radovan Chytracek <Radovan.Chytracek@cern.ch>
To: Amaya Lopez-Duran Viani <amaya@desy.de>; <roottalk@pcroot.cern.ch>
Sent: 11 сентября 2000 г. 10:20
Subject: RE: [ROOT] Iitialization of string characters


> Hi,
>
> This macro works for me in ROOT/Cint:
>
> {
>   gROOT->Reset();
>
>   const int MaxHistos = 24;
>
>   // Initialize array of pointers
>   char* HisXTit[MaxHistos] = {
>     "xCal",  "yCal", "yCal",
>     "xHES",  "yHES", "yHES",
>     "xCal",  "yCal", "yCal",
>     "rCal",  "rCal", "rCal",
>     "rHES",  "rHES", "rHES",
>     "rCal",  "rCal", "rCal",
>     "zCal",  "xCal", "xCal",
>     "yCal",  "yCal", "zCal"
>   };
>
>   int i;
>
>   for(i=0;i<MaxHistos;i++){
>     printf("%s\n",HisXTit[i]);
>   }
> }
>
> C++ compiler (MSVC++6.0) gives me the same result in the both cases.
>
> Radovan
>
>
> > I have tried to use the following initialization of string
> >
> >
> > {
> >   const int MaxHistos = 24;
> >   char HisXTit[MaxHistos][5] = {"xCal",  "yCal", "yCal",
> >                                 "xHES",  "yHES", "yHES",
> >                                 "xCal",  "yCal", "yCal",
> >                                 "rCal",  "rCal", "rCal",
> >                                 "rHES",  "rHES", "rHES",
> >                                 "rCal",  "rCal", "rCal",
> >                                 "zCal",  "xCal", "xCal",
> >                                 "yCal",  "yCal", "zCal"};
> >
> >   int i;
> >
> >   for(i=0;i<MaxHistos;i++){
> >     printf("%s\n",HisXTit[i]);
> >   }
> > }
> >
>
>



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