Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Code Block
bgColor#ffcccc
/* 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
bgColor#ccccff
/* 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.

...