1. Reading And Writing Lines

To Albert Brauneis ( And Others Interested),

1st : I am very very new to Euphoria
Welcome

2nd : c:\windows\temp.dat to c:\\windows\\temp.dat
You only need the \\ in your source code. The \ in the source allows you to
use special charcaters.

--- < Untested > ---
function add_bslash( sequence str )
integer i

        i = 1;
        while i <= length(str) do
                if str[i] = ‘\\’ then
                        str = str[1..i] & ‘\\’ & str[i+1..length(i)]
-- Rememeber str[a..a-1] produces an empty
                                sequence.
                        i = i + 1
                end if
        end while
        return str
end function
--- < End > ---

3rd : I am trying to make a simple program that opens a file and inputs it
line by line and prints it to the screen line by line.
--- < Untested > ---
function get_line( integer fn )
sequence val
integer c

        c = 0;
        val = {}
        while c >= 0 do
                c = getc( fn )
                if c != ‘\n’ and c != -1 then -- -1 means end of file.
                        val = val & c
                else
                        c = -1
                end if
        end while
        return val
end function

function put_line( integer fn, sequence str )

        for i = 1 to length(str) do
                puts( fn, str[i] )
        end for
end function
--- < End > ---
Because Euphoria is written in C and C uses #00 terminated strings and I’m
betting puts is pretty much the C one it will stop and any #00s in your
string so you may want to do it this way.




_______________________________________________________
Get your free, private e-mail at http://mail.excite.com/

new topic     » topic index » view message » categorize

Search



Quick Links

User menu

Not signed in.

Misc Menu