Re: Does this string processing work for you?




"Arjen Markus" <arjen.markus@xxxxxxxxxx> wrote in message
news:1127978370.237919.290330@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
>I strongly disagree with your conclusion that a few of the compliers
> discussed
> here "get it right". For one thing, why do they invariably conclude
> _eight_
> values have been read? Clearly, there are only seven valid values, so
> in an
> ideal world, the value of n should have been 7.
>

No it shud be 8 for same reason that the standard dictates that a do loop
shall exit +1 to its do terminus count when run to completion and lots of
code depends on that behaviour, this just repeats that KNOWN behaviour

> This gets rather tricky when you start using more complex
> read-statements:
>
> read( s, *, err=1 ) v(idvector)
>
> where idvector is a vector of indices
>
> There is no way in this statement that you can figure out how many
> data were read!
>

But your statement doesnt invoke a explicit list do loop, if you want to
index the output, below shows that usage

> Another thing where this goes awry, in my opinion, is the fact that the
> string must end in space+non-digit, rather than simply a non-digit.
>

But of course a (Cstring e.g.) MUST be provided EVERY time, which costs 1
statement to setup
The result is still just 2 statements which is fastest (probably) shortest,
clearest method to process a unknown string record and thus is worth the 1
statement to ALWAYS setup.

! -------------------
program process_string
character(200) :: s = '1,2,3,4,5,6,7'
integer :: v(7), n, indx(7) = [7:1:-1] ! small size(7) used
only to demo indx

s(len_trim(s)+1:) = ' ' // char(0) ! create padded
cstring
read (s,*,err=1) (v(indx(n)),n=1,size(v))

1 write (*,'(999I3)') n, v(1:n-1) ! and voila = 8 7 6 5 4 3 2 1
end program


.



Relevant Pages

  • Re: moving pairs
    ... what won't loop on it's own unless the whole machine's set position is ... board you setup pairs in any way ... a whole machine that altogether has one position to be in, ... Moving pairs do actually say they're a machine in a few ways. ...
    (comp.lang.c)
  • Re: moving pairs
    ... just be moving one that solves. ... what won't loop on it's own unless the whole machine's set position is ... board you setup pairs in any way ... a whole machine that altogether has one position to be in, ...
    (comp.lang.c)
  • Re: moving pairs
    ... just be moving one that solves. ... what won't loop on it's own unless the whole machine's set position is ... board you setup pairs in any way ... a whole machine that altogether has one position to be in, ...
    (comp.lang.c)
  • Re: moving pairs
    ... just be moving one that solves. ... what won't loop on it's own unless the whole machine's set position is ... board you setup pairs in any way ... a whole machine that altogether has one position to be in, ...
    (comp.lang.c)