Re: problem printing an array in a loop

Philippe Le Gal <[email protected]> Wed, 26 Mar 2008 08:55:12 +0100
Newsgroups gmane.text.clearsilver.general
Message-ID <[email protected]>
Hi Brandon

It works fine with the 'each' syntax.
I'll try the loop syntax too just to understand it.
Is there a bank of examples online with program in C and the corresponding cs 
syntaxe ?

Thanks

Philippe    

Le Wednesday 26 March 2008 07:59:26 Brandon Long, vous avez écrit :
> On 03/25/08 Eric Brunson uttered the following other thing:
> > Philippe Le Gal wrote:
> > > Hi,
> > >
> > > I try to generate an array filled in a c cgi like this :
> > >
> > >     char values[15][4];
> > >     int x;
> > >
> > >     // populate values
> > >     for (x = 0; x < 15; x++) {
> > >         sprintf(values[x], "%d", map[x]);
> > >     }
> > >
> > >
> > >     for (x = 0; x < 15; x++) {
> > >         hdf_set_valuef(cgi->hdf, "Values.%d=%s", x, values[x]);
> > >     }
> > >
> > > I can see that the hdf is filled with the values when debugging :
>
> [snip]
>
> > > But I need a loop to make the job. So I tried :
> > >
> > > <?cs loop:x=#0,#15 ?><?cs var:Values.x ?><?cs /loop ?>
>
> The right syntax here is:
> <?cs loop:x=#0,#15 ?><?cs var:Values[x] ?><?cs /loop ?>
>
> or even:
> <?cs loop:x=15 ?><?cs var:Values[x] ?><?cs /loop ?>
>
> though that's pretty gross (assumes start is 0).  I'm really not a fan
> of the loop syntax...
>
> > Have you tried:
> >
> > <?cs for: v in Values ?><?cs var: v ?><?cs /loop ?>
>
> The right one here is:
> <?cs each:v=Values ?><?cs var:v ?><?cs /loop ?>
>
> Brandon