Re: Help

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

On Wed, 28 Oct 1998 21:56:40 EST, Albert Brauneis <Dajawu36 at AOL.COM> wrote:

>Hello,
>
>I am very very new to Euphoria and 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. I can open files and read and write to them but looping until eof I have
>trouble with. I don't think there is an eof but I tried some things and I
>can't get it to work. So if you can post this simple program for me that would
>be great. Also say I want someone to type in a filename and they type in
>c:\windows\temp.dat is there a function or do I have to make my own that
>converts that to c:\\windows\\temp.dat??
>
Proving only that there is more than one way to program anything,
I submit the following fairly simple way to do what you want:

object file,line -- line *must* be declared as an object
atom fn

puts(1,"Filename:")      -- display a prompt
file = gets(0)           -- read input
file[length(file)] = ' ' -- kill l/f character appended to the input

-- if you want to hard-code a filename within your program
-- do replace the 3 lines above with the following line:
-- file = "C:\\EUPHORIA\\READ_ME.TXT"

clear_screen()
fn = open(file,"r")
if fn = -1 then puts(1,"File not found")
end if

while 1 do
   line = gets(fn)
   if atom(line) then exit -- eof
   end if
   puts(1,line)
end while

--  Regards,
--  Irv
Buses stop at bus stations,
Trains stop at train stations;
on my desk is a work station....

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

Search



Quick Links

User menu

Not signed in.

Misc Menu