difference between fgets and fgetl
11 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
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 commentaires
Réponses (1)
Walter Roberson
le 31 Déc 2012
Modifié(e) : Walter Roberson
le 31 Déc 2012
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 commentaires
Voir également
Catégories
En savoir plus sur Characters and Strings dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!