How to use filenum ...

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

For Alex Caracatsanis:

The correct code for this is instructive :

-- TESTED code ahead

include get.e

atom fn
sequence full_path, drive, file

puts(1, "enter drive letter: ")
drive = gets(0) -- get the drive letter in a sequence.
--It has a \n attached that will need to be stripped.
puts(1, "\nenter file name: ") -- start new line for better readability
file = gets(0) -- get the file name in a sequence
puts(1,"\n")
full_path = drive[1..length(drive)-1] & ":\\"
-- strip the \n and concatenate  the ":\\" to the end of the drive
full_path =  full_path & file[1..length(file)-1]
 -- concatenate the file name to the drive letter and ":\\"
-- This could also be coded as full_path &= file[1..length(file)-1]

fn = open( full_path, "w" )
if fn = -1 then
    -- file open error
else
   -- do your stuff
close(fn)


-- End of code


For this type of code, it is critical to use concatenation (&) rather than
append.

An example:

sequence a,b,c,d
a={1,2,3,4}  -- a four-element sequnce
b={5,6,7}  -- a three-element seuqnce
c=a&b  -- c is equal to {1,2,3,4,5,6,7} (a seven-element sequence)
d=append(a,b)  -- d is equal to {1,2,3,4,{5,6,7}}
-- (a five-element sequence with a subsequence)

-- Mike Nelson

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

Search



Quick Links

User menu

Not signed in.

Misc Menu