From octave-maintainers-request at bevo dot che dot wisc dot edu Thu Jul 20 14:22:56 2000 Subject: Bug in 2.1.30 and 2.1.31 -- fscanf in "C" compatibility mode From: "John W. Eaton" To: Joao Cardoso Cc: "octave-maintainers at bevo dot che dot wisc dot edu" Date: Thu, 20 Jul 2000 14:22:58 -0500 (CDT) On 20-Jul-2000, Joao Cardoso wrote: | The following ilustrate the bug on a two line file: | | ---po---- | One: 1 | Two: 2 | --------- | | octave:1> f=fopen("po","r"); | octave:2> a=fscanf(f,"One: %d\n") | a = 1 | octave:3> ftell(f) | ans = 7 | octave:4> a=fscanf(f,"Two: %d\n") | a = 2 | octave:5> frewind(f) | ans = 0 | octave:6> a=fscanf(f,"One: %d\n","C") | a = 1 | octave:7> ftell(f) | ans = -1 | octave:8> frewind(f) | ans = 0 | octave:9> a=fscanf(f,"One: %d","C") | a = 1 | octave:10> ftell(f) | ans = -1 | | And thus the second file line can't be read. | | If the file is read line by line with 'fgetl' and than 'sscanf', | everything is OK. I think the following patch should fix this problem. I've checked it in to the CVS archive. Thanks, jwe 2000-07-20 John W. Eaton * oct-stream.cc (octave_base_stream::oscanf): Advance to next format element before attempting to pick up any trailing stuff. Index: oct-stream.cc =================================================================== RCS file: /usr/local/cvsroot/octave/src/oct-stream.cc,v retrieving revision 1.65 diff -u -r1.65 oct-stream.cc --- oct-stream.cc 2000/03/31 23:33:26 1.65 +++ oct-stream.cc 2000/07/20 19:18:12 at @ -1897,6 +1897,9 @@ if (ok () && len > nconv) { octave_value tmp; + + elt = fmt_list.next (); + do_oscanf (elt, tmp); } }