+ 1

Prevent infinite loop in scanf function

Hi If we have a scanf(%d , &x) for integer but user input a char the program goes into a infinite loop How can I prevent that For example if user inputs a char the program ignore it or warn user to input integers Thanks

7th Dec 2020, 8:04 AM
reza jannati
reza jannati - avatar
3 ответов
0
Martin Taylor when scanf gets a char from input then repeats the scanf but do not get anything and saves the last character and again and again
7th Dec 2020, 8:45 AM
reza jannati
reza jannati - avatar