0
Please someone help me with The following C code regarding input validation.
I need to validate the input as numeric and greater than zero and if not, then retake the input but It only takes input One time and goes into infinite loop after that, how do I prevent this please help. https://code.sololearn.com/cyX13zQLnkWN/?ref=app
4 Antworten
+ 2
The issue here is that when scanf fails to read input due to type mismatch, the input character remains within the input stream. One way to clear the input stream is through the use of getchar(). In the example below, we attempt to clear stdin until a newline or EOF is met.
https://code.sololearn.com/cfFdq1K9SMB7/?ref=app
0
I have tried it in other compilers, the same thing happens every time. please help!
0
1. I'm using goto to jump to line where I took the input to take input again correctly.
2. Please suggest the right way.
0
Thanks Hatsy rei got it😀