help-octave
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Reading to end-of-file


From: Eyal Doron
Subject: Reading to end-of-file
Date: Tue, 5 Sep 1995 16:07:32 +0100 (MET DST)

Hi all!

Suppose I have a file try.dat:

 1 2
 2 3
 3 4
 4 5

and I want to read it using fscanf, but I don't know the length. I try

function a=try(f);
%
while !feof(f)
  s=fscanf(f,"%s"); g=fscanf(f,"%g");
  printf("%s, %g\n",s,g)
end

but this fails with an error, 

warning: fscanf: end of file reached before final conversion
error: value on right hand side of assignment is undefined
error: evaluating assignment expression near line 4, column 4
error: evaluating while command near line 3, column 1
error: called from `try' in file `/us0/theo/doron/tmp/try.m'

I found no way around this, even unwind_protect is no help inside a 
function. What to do?

It seems fscanf behaves quite badly at eof. IMHO it should not fail,
but explicitly return [] so that assignments don't crash.

P.S. This is just an example, so don't tell me there are other ways
to load this file!

Thanks,
    Eyal Doron

reply via email to

[Prev in Thread] Current Thread [Next in Thread]