필터 지우기
필터 지우기

open file, read a line then, rewind a line

조회 수: 17 (최근 30일)
Sam
Sam 2012년 11월 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?
  댓글 수: 2
Azzi Abdelmalek
Azzi Abdelmalek 2012년 11월 30일
What is your goal?
Sam
Sam 2012년 11월 30일
say this is the text file i want to read
my line 1
my line 2
my line 3
my line 4
say after some steps, fgetl(fid) would return 'my line 3', then what should I do so when I call fgetl(fid) after this, it would still return 'my line 3'?

댓글을 달려면 로그인하십시오.

답변 (1개)

Matt J
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
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 CenterFile 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!

Translated by