Liste des Groupes | Revenir à cl c |
On 2/10/25 20:03, Lawrence D'Oliveiro wrote:
>On Mon, 10 Feb 2025 13:58:05 -0500, James Kuyper wrote:
I don't see the contradiction. If "no characters are read into the
array", there is no such thing as "the last byte read into the array",
so a null byte has no location where it should be written. Therefore,
there's no reason for changing the contents of the array.
What if the array is only big enough for one byte? In this case, no
characters can be read into it. Is a trailing null inserted in this
case?
"The fgets function reads at most one less than the number of characters
specified by n from the stream pointed to by stream into the array
pointed to by s." (7.32.7.2p2)
If the buffer length is 1, "at most one less than the number ...
specified" is 0. Therefore, fgets() cannot read any characters into the
buffer, no matter what the contents of the input stream are. Again,
since there is no "last byte read into the array", there is no location
where a null byte should be written.
Les messages affichés proviennent d'usenet.