Open hsh-notes opened 4 years ago
Please use the fflush function in order to clear the input buffer for next input in character array.
On 14-Jun-2020, at 1:38 AM, skkuhi notifications@github.com wrote:
Hello TA. I don't know why scanf doesn't work. All header files work well. Furthermore, even at the top of the code, scanf worked well. I write the code like this picture.
Like the following debug console, I put scanf in the code, but the program ends right away.
Could you tell me why? There is no error that visual studio tells me. I tried many ways such as restarting the computer, using getchar, but I still could not scan 'x'.
— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub, or unsubscribe.
However, I defined 'x' as char type.
After a few more attempts, I found that only the first scanf was ignored. So if I write scanf twice, the program works only once. Can I write the code like this?
it's an issue in the compiler and has nothing to do with code. from my experience, you can't fix it unless you change your compiler from MICROSOFT VS COMPILER to GCC or GNU. I think you might not know that so just use codeblocks ( it is compatible with visual studio, I tested it) and it has no issues.
Thank you very much for your detailed answer.
Hello TA. I don't know why scanf doesn't work. All header files work well. Furthermore, even at the top of the code, scanf worked well. I write the code like this picture.
![image](https://user-images.githubusercontent.com/66879725/84574020-f56b0d00-adde-11ea-98cd-2d983ee234f6.png)
Like the following debug console, I put scanf in the code, but the program ends right away.![image](https://user-images.githubusercontent.com/66879725/84573999-d79da800-adde-11ea-9041-7a5bacc44ea1.png)
Could you tell me why? There is no error that visual studio tells me. I tried many ways such as restarting the computer, using getchar, but I still could not scan 'x'.