...
Code Block | ||
---|---|---|
| ||
/* some device used for both input and output */ char const *filename = "/dev/device2"; FILE *file = fopen(filename, "rb+"); if (file == NULL) { /* handle error */ } /* write to file stream */ /* read response from file stream */ fclose(file); |
However, the output buffer is not flushed before receiving input back from the stream, so the data may not have actually been sent, resulting in unexpected behavior.
...
Code Block | ||
---|---|---|
| ||
/* some device used for both input and output */ char const *filename = "/dev/device2"; FILE *file = fopen(filename, "rb+"); if (file == NULL) { /* handle error */ ] /* write to file stream */ fflush(file); /* read response from file stream */ fclose(file); |
This ensures that all data has been cleared from the buffer before continuing.
...