Liste des Groupes | Revenir à cl c |
Note also that `fgets` is not permitted to assume that the limit value (the second parameter) correctly describes the accessible size of the buffer. E.g. for this reason it is not permitted to zero-out the buffer before reading. For example, this code is valid and has defined behavior... and this part of specification effectively guarantees, that any [tail] portion of the buffer not overwritten by the characters obtained from file, will remain unchanged. If `fgets` reads 5 characters from the file, only first 6 characters of the buffer will be overwritten, while the rest is guaranteed to remain untouched. If `fgets` reads nothing (instant end-of-file), the entire buffer remains untouched.
char buffer[10];
fgets(buffer, 1000, f);
provided the current line of the file fits into `char[10]`. I.e. even though we "lied" to `fgets` about the limit, it is still required to work correctly if the actual data fits into the actual buffer.
Les messages affichés proviennent d'usenet.