open file, read a line then, rewind a line
20 次查看(过去 30 天)
显示 更早的评论
after fgetl(fid), the file position indicatior will be moved to the next line in the file, how could I rewind the indicator back 1 line in the file so when I call fgetl(fid) the second time it would return the same line?
回答(1 个)
Matt J
2012-11-30
编辑:Matt J
2012-11-30
Use FTELL to measure the position in bytes of each line. Then use FREWIND and/or FSEEK to go to the desired position.
1 个评论
Walter Roberson
2012-11-30
Technical note:
If a file is opened with 'rt', which should be used for text files, then the value returned by ftell() is an arbitrary "token" rather than a file offset in bytes. Using the same token will get you to the same position, but you cannot do computations on the tokens.
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Low-Level File I/O 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!