Re: (No Subject)

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

Irv Mullins writes:
> This is close to being a *bug* in Euphoria, or at least a
> real puzzle. I just tried this:
> object s
> atom fn
> fn = open("TEST.TXT","r")
> while 1 do
>  s = gets(fn)
>  if atom(s) then exit
>  end if
>  puts(1,s)
> end while
> It reads and prints all the lines in my test file, *including* the
> last line which does NOT end in a linefeed or c/r. (I checked
> it with a hex editor - in fact, made test files with 4 different
> editors, plus the dos "copy con test.txt" command)
> Lots of times, however, the same code _has_ dropped
> the last line. Whazzup?
> (I know about using getc in a loop, but why go to all
> that trouble? This is supposed to be a high level
> language.)

If you can give me an example where gets()
fails (drops the last line), I'd be happy to investigate.

gets() is supposed to return the whole line including '\n'
if there is one. The last line in a file might not have
a '\n', so gets() will return all the characters on that line,
but there won't be a '\n' on the end.

Some editors do funny things when the last line in
your file does not end with '\n'.  ed.ex will
add a '\n' to your line. ee.ex seems to
drop the last character on the line that's missing the \n.
Are you reading David? I tried:

junk.ex:
puts(1, "line1\nline2")   -- missing final \n

ex junk >junk.dat

ex ee junk.dat

and found the '2' in line2 was missing.

Regards,
     Rob Craig
     Rapid Deployment Software

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

Search



Quick Links

User menu

Not signed in.

Misc Menu