Sujet : Re: Buffer contents well-defined after fgets() reaches EOF ?
De : janis_papanagnou+ng (at) *nospam* hotmail.com (Janis Papanagnou)
Groupes : comp.lang.cDate : 14. Feb 2025, 21:02:19
Autres entêtes
Organisation : A noiseless patient Spider
Message-ID : <voo7gd$3k9oh$1@dont-email.me>
References : 1 2 3 4 5 6 7 8 9 10 11
User-Agent : Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Thunderbird/45.8.0
On 14.02.2025 20:38, James Kuyper wrote:
As with several of the string processing functions, I think fgets()
would be better if it returned a pointer to the end of the data that was
read in, rather than to the beginning.
Yes, that's another option. The language designer have to decide which
behavior is more useful. There's pros and cons, IMO. On the minus side
would be that the origin of the string gets lost that way. (Of course
you can adjust your code then to keep a copy. But any way implemented,
you need to adjust your code according to how the function is defined.)
The chaining you talk about does
not, in general, work properly if the return value from fgets() is NULL,
Yes.
or the entire buffer was filled without writing a null character.
I read the man page that as if that at least would be guaranteed:
"A terminating null byte ('\0') is stored
after the last character in the buffer."
(also in cases where no EOL or EOF is read).
Janis