??? 06/07/07 05:36 Modified: 06/07/07 05:37 Read: times |
#140368 - still better than scanf() Responding to: ???'s previous message |
gets() is bad becuase it can over run the input butter. This is because it does not ask how big the buffer is. I would not use it either.
My preference is getc(). Read the bytes one at a time ( No Blocking). Dump it if the bytes do not arrive before the time out Verify they are OK, then convert. This avoids: 1234123412341234 // 123412341234123 // lost byte 12341234123412341 // Extra byte ! // Noise 123a1234123412341 // Invalid data I would: X1234123412341234x // Add a packet Start and Stop Delimiter X1234123412341234x00 // Tack on a checksum or CRC RS-232 does not guarantee error free delivery of data. |