Pelles C forum

C language => Beginner questions => Topic started by: draz on September 21, 2010, 10:23:43 AM

Title: how do I perform scanf twice in a while loop?
Post by: draz on September 21, 2010, 10:23:43 AM
I have a scanf inside a while loop so that the user can put in input multiple times. I have a piece of code inside the loop to prevent an eternal loop. because of this, the program can only be used ten times before it quits. however, I want to replace that with a second scanf where the user can choose wheather or not to continue using the program. the problem is, that when I have a second scanf in the code, as soon as I press enter for the first scanf, it skips through the rest of the code and starts the loop over again, ignoring the second scanf. what is wrong?
Title: Re: how do I perform scanf twice in a while loop?
Post by: Stefan Pendl on September 21, 2010, 11:07:59 AM
Enter or Return does send two characters, so you will have to filter that out.

I think there are examples posted, just search for scanf.