fgetl, textscan, and the file position indicator

Is a construct like this legal?
It doen't return any error, but the "file position indicator" is not advanced as it should. I read a text file CRLF for new line.
fid = fopen( ... );
str = fgetl( fid );
cac = textscan( fid, ... );
...
str = fgetl( fid );
cac = textscan( fid, ... );
fclose( fid )

 Accepted Answer

Walter Roberson
Walter Roberson on 7 Sep 2012
Edited: Walter Roberson on 7 Sep 2012
That series is valid, yes.
Did you open the file with 'rt' instead of 'r' in order to account for the CRLF ?
Also note that if you use a count for textscan() then the file position will be left after the last format code is used, before the newline for that line (unless the end of format matches newline)

More Answers (0)

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!