difference between fgets and fgetl
7 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
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 comentarios
Respuestas (1)
Walter Roberson
el 31 de Dic. de 2012
Editada: Walter Roberson
el 31 de Dic. de 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 comentarios
Ver también
Categorías
Más información sobre Characters and Strings en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!