How do I detect line number while reading a file?
9 ビュー (過去 30 日間)
古いコメントを表示
Is there a way to detect the line number while reading a text file? ftell will give a pointer in the file, but not the line number.
Thanks
0 件のコメント
採用された回答
per isakson
2020 年 6 月 15 日
There is no function that takes the output of ftell() and returns the line number.
One has to keep track of the line number with user code. However, that is hard to combine with the use of fseek().
2 件のコメント
Walter Roberson
2020 年 6 月 15 日
The I/O systems used by Windows, Mac, and Linux, do not keep track of the line number. Anything keeping track of the line number would have to be layered on top of the I/O system.
The situation is more tricky than it first appears, since repositioning is permitted, and since it is (generally speaking) permitted to write in the middle of a file (which can change the line numbering for anything after that point), and multiple processes can write into the same file.
その他の回答 (0 件)
参考
カテゴリ
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!