...
In this compliant solution, fflushfseek()
is called in between the output and input, eliminating the undefined behavior.
Code Block | ||
---|---|---|
| ||
char data[BUFSIZ]; char append_data[BUFSIZ]; char *file_name; FILE *file; /* initialize file_name */ file = fopen(file_name, "a+"); if (file == NULL) { /* handle error */ } /* initialize append_data */ if (fwrite(append_data, BUFSIZ, 1, file) != BUFSIZ) { /* Handle error */ } fflush(file);if (fseek(stream, 0L, SEEK_SET) != 0) { /* Handle Error */ } if (fread(data, BUFSIZ, 1, file) != 0) { /* handle there not being data */ } fclose(file); |
...