1. Problem with printf

Printf works fine in my app, with sequence slice to limit the number of 
characters actually printed:

printf(1,"%8s",data_array[rec_no][1..6])  for example.

For reasons other than coding elegance, I need to have the arguments of 
printf read from another array. It works fine for everything except the 
slice specification. The interpreter will not accept 1..6 read into the 
final [  ] via a subscripted array element.
As of now, I am using "if" statements to select between several 
different printf's with different sequence slice specs. Is there a 
better way?

Allen

new topic     » topic index » view message » categorize

2. Re: Problem with printf

Allen Robnett wrote:
> Printf works fine in my app, with sequence slice to limit the number of 
> characters actually printed:
> 
> printf(1,"%8s",data_array[rec_no][1..6])  for example.

You say it works fine, but I don't believe you.
Please add braces:

printf(1,"%8s",{data_array[rec_no][1..6]})

I know it looks strange, but in Euphoria
it logically has to work this way. You have one %,
so you should supply a sequence of
length 1 (at the top-level), not 6, as the third argument.
Otherwise only the first character of 6 will be printed.

Everyone (including myself) falls into this trap
sooner or later.

Regards,
    Rob Craig
    Rapid Deployment Software
    http://www.RapidEuphoria.com

new topic     » goto parent     » topic index » view message » categorize

3. Re: Problem with printf

Allen Robnett wrote:

>
>
>Printf works fine in my app, with sequence slice to limit the number of 
>characters actually printed:
>
>printf(1,"%8s",data_array[rec_no][1..6])  for example.
>
>For reasons other than coding elegance, I need to have the arguments of 
>printf read from another array. It works fine for everything except the 
>slice specification. The interpreter will not accept 1..6 read into the 
>final [  ] via a subscripted array element.
>  
>
Do you want something like this:

atom x,y
x=1
y=6
printf(1,"%8s",data_array[rec_no][x..y]

or

x = {1,6}
printf(1,"%8s",data_array[rec_no][x[1]..x[2]]

Either should work.

new topic     » goto parent     » topic index » view message » categorize

4. Re: Problem with printf

----- Original Message ----- 
From: "C. K. Lester" <euphoric at cklester.com>
To: <EUforum at topica.com>
Subject: Re: Problem with printf


> 
> 
> Allen Robnett wrote:
> 
> >
> >Printf works fine in my app, with sequence slice to limit the number of 
> >characters actually printed:
> >
> >printf(1,"%8s",data_array[rec_no][1..6])  for example.
> >
> >For reasons other than coding elegance, I need to have the arguments of 
> >printf read from another array. It works fine for everything except the 
> >slice specification. The interpreter will not accept 1..6 read into the 
> >final [  ] via a subscripted array element.
> >  
> >
> Do you want something like this:
> 
> atom x,y
> x=1
> y=6
> printf(1,"%8s",data_array[rec_no][x..y]
> 
> or
> 
> x = {1,6}
> printf(1,"%8s",data_array[rec_no][x[1]..x[2]]
> 
> Either should work.

Or if the first element is always #1, then this is suffcient...

 integer len

 len=6 -- or whatever...
 printf(1,"%8s",{data_array[rec_no][1..len]})

-- 
Derek

new topic     » goto parent     » topic index » view message » categorize

5. Re: Problem with printf

On Wed, 31 Dec 2003 03:17:26 +0000, Allen Robnett
<alrobnett at alumni.princeton.edu> wrote:

>The interpreter will not accept 1..6 read into the 
>final [  ] via a subscripted array element.
Can you post the code and error message please

Pete

new topic     » goto parent     » topic index » view message » categorize

Search



Quick Links

User menu

Not signed in.

Misc Menu