...
| Code Block | ||
|---|---|---|
| ||
char buf[BUFSIZ + 1];
if (fgets(buf, sizeof(buf), fp)) {
buf[strlen(buf) - 1] = '\0';
}
else {
/* Handle error condition */
}
|
However, if the last character in buf is not a newline, this code overwrites an otherwise-valid character.
...