How to stop program crashing

+1 vote
asked Mar 10, 2019 by Kyle (200 points)
Every time I enter a character for my switch statement it just crashes is there anyway to stop this

1 Answer

0 votes
answered Mar 12, 2019 by 201851116 SHAH JAINILKUMAR VIPULBHAI (540 points)
selected Mar 12, 2019 by Kyle
Best answer
please use fflush(stdin); whenever you are inserting the string, You have to use fflush because if you are entering the enter so at that time switch statement takes the '\n' as a character input, and that's why your program had been crashed.....
commented Mar 13, 2019 by IamAkashGhosh (140 points)
If it is C language you need to write "fflush(stdin);" after reading the character to clear the buffer. But it may be happening for some other reason to. So the code is important to analyze.
Welcome to OnlineGDB Q&A, where you can ask questions related to programming and OnlineGDB IDE and and receive answers from other members of the community.