Important changes to forums and questions
All forums and questions are now archived. To start a new conversation or read the latest updates go to forums.mbed.com.
8 years, 7 months ago.
about serial buffers
is there any function through which we can clear the serial buffer, after reading the data by scanf(). i am writing a program where i am sending only one string at time. initially before sending the string output of readable() is zero that is fine becoz no data is present in the buffer, when string is received in the buffers readable() becomes 1. now after taking the string from buffers by scanf function output of readable() should be zero bt its not. it is again showing value 1. plzzzz give the answer...
1 Answer
8 years, 7 months ago.
scanf("%s") will read up to the first whitespace character and stop. If the transmitted string ends with "\r\n" then you have two whitespaces at the end. So you buffer isn't empty because it still contains two bytes, '\r' and '\n'.
google "clear serial buffer scanf" provides some clear insight
posted by Robert Spilleboudt 29 Apr 2016