Liste des Groupes | Revenir à cl c |
On 2/10/25 23:54, Lawrence D'Oliveiro wrote:On Mon, 10 Feb 2025 22:33:03 -0500, James Kuyper wrote:...>"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.
Have you tried it? I have.
I just tried it, using gcc and found that fgets() does set the first
byte of the buffer to a null character. Therefore, it doesn't conform to
the requirements of the standard. That's not particularly surprising -
calling fgets with useless arguments isn't something that I'd expect to
be a high priority on their pre-delivery tests.
Les messages affichés proviennent d'usenet.