Hi Thorsten,

On 2011-05-30 13:53, Thorsten Behrens wrote:
> Hi Arjen!
> 
>>> BTW: You can also define a constant for the string length instead of  
>>> using  integer literals in the code.
>> Good thinking! Actually, as I look at the code, I see that it presumes
>> that lines are never longer than 30 characters.
> 
> If I understand http://en.wikipedia.org/wiki/Fgets corrytly, then the code  
> assumes lines to be no longer than 29 characters because fgets always  
> appends a NUL-byte to the string read (or do I misunderstand something  
> here?). This is why I also thought that you could omit changing the  
> lineending to a NUL-byte. Howevere, just changing all /r, /n to NUL is the  
> safest way, I guess.

Yes, that is true.

> 
>> If they are, the reading process will fail in an uneasy way. I will try
>> and take care of that too.
> 
> Why does it fail in an uneasy way? Will strlen not terminate, because  
> there is no NUL-byte in the string returned by fgets then?
> 

Because the file pointer will not be moved to the end of the line. The
next read would pick up where it left off, so it would read the rest
of the same line, not the next line. That results in errors that are
probably difficult to detect.

I have written a small test program that reads 30 characters and then
skips the rest of the line. Not entirely trivial but it works, so I
will apply that.

Regards,

Arjen
 

DISCLAIMER: This message is intended exclusively for the addressee(s) and may 
contain confidential and privileged information. If you are not the intended 
recipient please notify the sender immediately and destroy this message. 
Unauthorized use, disclosure or copying of this message is strictly prohibited.
The foundation 'Stichting Deltares', which has its seat at Delft, The 
Netherlands, Commercial Registration Number 41146461, is not liable in any way 
whatsoever for consequences and/or damages resulting from the improper, 
incomplete and untimely dispatch, receipt and/or content of this e-mail.





------------------------------------------------------------------------------
vRanger cuts backup time in half-while increasing security.
With the market-leading solution for virtual backup and recovery, 
you get blazing-fast, flexible, and affordable data protection.
Download your free trial now. 
http://p.sf.net/sfu/quest-d2dcopy1
_______________________________________________
Plplot-general mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/plplot-general

Reply via email to