help-octave
[Top][All Lists]
Advanced

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

how does fscanf with "C" work?


From: Francesco Potortì
Subject: how does fscanf with "C" work?
Date: Mon, 08 Sep 2014 11:56:45 +0200

I wrote:

>In the code, fgetl is just used to get rid of the header line.  My
>problem is with fscanf, which in my plan should read all the subsequent
>lines, but only reads the first one after the header line.

I'll try to be more specific.  If I get no answer from this list, I'll
submit a bug report.

I create a text file made of four lines, like this:

===File ~/math/workarea/test.txt============================
field1, field2, field3, field4
A,        a,        1,       1.0,
B,        b,        2,        2.0,
C,        c,        3,        3.0,
============================================================

Then this is what i get:

octave> version
ans = 3.8.2
octave> fid=fopen("test.txt");
octave> fgetl(fid);
octave> [v1, v2, v3, v4, count, errmsg] = fscanf(fid, "%s%s%d,%f,", "C")
v1 = A,
v2 = a,
v3 =  1
v4 =  1
count =  4
errmsg = 
octave> fclose(fid);

The result is that fscanf reads a single line from the file
(specifically, the second line).  What I expected was fscanf to read all
the subsequent lines (second, third and fourth) and put the results in
the four vectors given as output.

The same happens if I use a character conversion rather than a string
conversion:

octave> fid=fopen("test.txt");
octave> fgetl(fid);
octave> [v1, v2, v3, v4, count, errmsg] = fscanf(fid, "%c, %c,%d,%f,\n", "C")
v1 = A
v2 = a
v3 =  1
v4 =  1
count =  4
errmsg = 
octave> fclose(fid);

So the question is: is fscanf with the "C" calling convention intended
and able to read multi-line input?

Whatever the answer, a clarification of the manual is needed.  I can
contribute to clarifying the manual, once I understand how fscanf with
"C" is meant to behave.

-- 
Francesco Potortì (ricercatore)        Voice:  +39.050.621.3058
ISTI - Area della ricerca CNR          Mobile: +39.348.8283.107
via G. Moruzzi 1, I-56124 Pisa         Skype:  wnlabisti
(entrance 20, 1st floor, room C71)     Web:    http://fly.isti.cnr.it



reply via email to

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