hello, there's a little problem with the scanf-function. My program
... scanf("%u",&A); ...
CLR ?C?charloaded RET
there's a little problem with the scanf-function Absolutely not. The only problem here is that you haven't learned enough about scanf() before you started using it. How to clear the scanf-input-stream? You don't, for two reasons. First, because there is no such thing as a scanf-input-stream. That stream is in no way special to scanf. It is, for all practical intents and purposes, the standard input stream, a.k.a. stdin. Second, because stdin cannot meaningfully be "cleared". The issue you've stumbled over is the reason that scanf() is very rarely used in production-grade C programs. They use fgets and ssscanf() instead.
It is interesting to note that the Keil C51 does have an input buffer that needs to be cleared. http://keil.com/support/docs/2017.htm
Now i have a little workaround. Maybe it is helpful for some user.
while(1) { printf("Enter your personal secret Hex-key!\n"); if (scanf("%X",&A)) break; scanf("%*"); //Clearing scanf input stream }
the Keil C51 does have an input buffer that needs to be cleared. That's an over-interpretaion of that support note you found. Yes, it does have a buffer, which you can clear if you want to. But by no means does that imply it needs to be cleared. In a nutshell: if you feel a need to clear stdin, you've quite invariably done something wrong before, i.e. you're now trying to fix symptoms instead of treating the disease. Basically, scanf() directly into any other format but strings is hardly ever an appropriate means of reading input from a non-deterministic source, e.g. a human operator. I.e. if you don't know for sure that the input will exactly match your scanf() format, every time, then scanf() is the wrong function to use. As I already indicated, error-prone input pretty much has to be read as a string, which you then sscanf().
Hans,
That's an over-interpretaion of that support note you found. Yes, it does have a buffer, which you can clear if you want to. But by no means does that imply it needs to be cleared