...
In this noncompliant code example, an error flag is set upon fgets() failure.:
| Code Block | ||||
|---|---|---|---|---|
| ||||
char buf[BUFSIZ];
FILE *file;
/* Initialize file */
if (fgets(buf, sizeof(buf), file) == NULL) {
/* Set error flag and continue */
}
|
...
In this compliant solution, buf is set to an empty string if fgets() fails. The equivalent solution for fgetws() would set buf to an empty wide string.:
| Code Block | ||||
|---|---|---|---|---|
| ||||
char buf[BUFSIZ];
FILE *file;
/* Initialize file */
if (fgets(buf, sizeof(buf), file) == NULL) {
/* Set error flag and continue */
*buf = '\0';
}
|
...