...
Code Block | ||
---|---|---|
| ||
/* some device used for both input and output */ char const *filename = "/dev/device2"; FILE *ptrfile = fopen(filename, "rb+"); /* write to ptr'sfile stream */ /* read response from ptr'sfile stream */ |
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 *ptrfile = fopen(filename, "rb+"); /* write to ptr'sfile stream */ fflush(ptrfile); /* read response from ptr'sfile stream */ |
This ensures that all data has been cleared from the buffer before continuing.
...