difference between fgets and fgetl
3 ビュー (過去 30 日間)
古いコメントを表示
I was studying fgets and fgetl and i totally did not understand the difference between these two commands. Can u explain it and give a small example? Thanx in advance.
HAPPY NEW YEAR!!!!
0 件のコメント
回答 (1 件)
Walter Roberson
2012 年 12 月 31 日
編集済み: Walter Roberson
2012 年 12 月 31 日
fgets() leaves the end-of-line characters in the string that is returned; fgetl() removes them from what is returned.
For example, if we let \r\n represent the end-of-line stored, then if the line in the file is
This is a test.\r\n
then fgets() would return
'This is a test.\r\n'
Not literal '\' 'r' '\' 'n' but the characte-return and end-of-line character,
['This is a test.' char(13) char(10)]
which is
sprintf('This is a test.\r\n')
On the other hand, fgetl() for the same line would return just
'This is a test.'
The only reason I have ever had to use fgets() was on systems old enough that they did not provide an fgetl() call. It isn't that I cannot think of any reason to use it, but in those few cases, it almost always turns out to be better to read as binary instead of as text.
0 件のコメント
参考
カテゴリ
Help Center および File Exchange で Characters and Strings についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!