lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


--- Shmuel Zeigerman <shmuz@actcom.co.il> wrote:
> Here is an fgets specification from The Open Group:
> 
> > The fgets() function shall read bytes from stream
> into the array
> > pointed to by s, until n-1 bytes are read, or a
> <newline> is read
> > and transferred to s, or an end-of-file condition
> is encountered.
> > The string is then terminated with a null byte.
> 
>  From this specification, it is quite obvious that
> only <newline> is 
> special in the input stream.
> 
I have a very different reading. In fact, I think null
is a special case as C strings are null terminated.
Thus it implicitly means that fgets() would stop at
null OR '\n'. Especially the last line where it said a
final NULL would be appended. 

Think if it doesn't stop at NULL of the input, then
anything beyond that is still invisible as caller of
this function expects the string to be a C string(i.e.
null terminated). So what is the point to read beyond
that ? If fact, without reading beyond that, a loop
can still read all the contents(sans NULL and \n) but
that still matches the 'lines of string' expectation
in C.

__________________________________________________
Do You Yahoo!?
Tired of spam?  Yahoo! Mail has the best spam protection around 
http://mail.yahoo.com