Expected file position after FSCANF conversion failure
Show older comments
Suppose the file data.txt contains the lines
--VarX
0.0 0.0 1.5 10.3
Is there an expected output of the following script
fid = fopen('data.txt');
[v, n] = fscanf(fid, '%f');
ftell(fid)
fclose(fid);
? Obviously, the FSCANF call will fail to convert any floating point numbers upon encountering the '--' string whence isempty(v) and n==0. However, I'm currently most concerned about the FTELL call. In MATLABs 7.7 (R2008b) and 7.9 (R2009b), FTELL returns 1 while MATLABs 7.10 (R2010a) and 7.13 (R2011b) both return 0.
In other words, R2009b (and earlier editions) advances the file pointer one byte, presumably because '-' is a valid leading character sequence of a (negative) floating point number. Later M-editions do apparently not advance the file pointer however, presumably because '--' is not a valid leading character sequence of a floating point number.
So, to repeat my above question: is there any defined behaviour with respect to FTELL in case of FSCANF conversion failure and, if so, did this behaviour change between R2009b and later editions of MATLAB? I cannot find anything in doc fscanf, doc ftell or the release notes.
As far as I can tell, MathWorks Technical Solution ID 1-426ARH is related to this question, but does not appear to be exactly the same thing. Am I just misreading the information therein?
PS Before you ask: For various reasons (unrelated to this particular issue) I cannot simply use
textscan(fid, '%f', 'CommentStyle', '--')
in the general case I'm trying to solve.
Accepted Answer
More Answers (0)
Categories
Find more on MATLAB Compiler in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!