I am writing a function where I only need to obtain a single digit, I decided to use getchar() instead of scanf().
However since I only need one character I did not use an array to obtain it. This causes a problem because I dont have a loop to find the '/n' character. To make sure my buffer is cleared before using getchar() again, I wrote this:
while (getchar() != '\n'){}
It works as I need it to, but is this the "correct" way to go about this problem?
I tried using fflush(stdin), but it seems to not have any effect.
Thank you for all replies, I check the comments often and would love to answer questions.