Re: Text lines into an array of unknown size

new topic     » goto parent     » topic index » view thread      » older message » newer message

Hi K=E5re, you wrote:

> as new commer from rexx to Euphoria

Welcome!

> I see many nice and semilare options and a richness of WinOS options
> but I have some basic newcommer problems on 'sequence a array'
>
> I want to open a file of text of unknown size and put all lines into
> an array where every line can be manipulated but I cannot get it right...=


There are no real "arrays" in Euphoria, but you can think of a sequence
as "very flexible array-like" data type.
Since the numbers of lines in a text file normally is not know before
reading the file, a sequence is much easier to use for reading a text
file line by line, than an array (no dim/redim required).

[code snipped]

> Where do I get it wrong!!! Probably a newcommers init problem but I
> would like some explane...

This is how I would do it:


        constant ERROR =3D 2
        integer count, file
        sequence tx
        object line

        file =3D open("c:/rexx/rxcalibur.txt", "r")
        if file =3D -1 then
           puts(ERROR, "couldn't open text file\n")
           abort(1)     -- end of program, exit code 1
        end if

        count =3D 0
        tx =3D {}
        while 1 do
           line =3D gets(file)
           if atom(line) then
              exit
           end if
           count +=3D 1
           tx =3D append(tx, line)
        end while
        close(file)

        printf(1, "available lines: %d\n\n", {count})
        for i =3D 1 to count do
           puts(1, tx[i])
        end for


Best regards,
   Juergen

--=20
 /"\  ASCII ribbon campain  |
 \ /  against HTML in       |  This message has been ROT-13 encrypted
  X   e-mail and news,      |  twice for higher security.
 / \  and unneeded MIME     |

new topic     » goto parent     » topic index » view thread      » older message » newer message

Search



Quick Links

User menu

Not signed in.

Misc Menu