...
This compliant solution checks to make sure the first character in the buf array is not a NULL before modifying it based on data obtained by the results of strlen().
| Code Block | ||
|---|---|---|
| ||
char buf[1024];
if (fgets(buf, sizeof(buf), fp) != NULL) {
if (buf[0] != '\0' && buf[strlen(buf) - 1] == '\n')
buf[strlen(buf) - 1] = '\0';
}
|
...