NO

Author Topic: how do I perform scanf twice in a while loop?  (Read 2994 times)

draz

  • Guest
how do I perform scanf twice in a while loop?
« 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?

Offline Stefan Pendl

  • Global Moderator
  • Member
  • *****
  • Posts: 582
    • Homepage
Re: how do I perform scanf twice in a while loop?
« Reply #1 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.
---
Stefan

Proud member of the UltraDefrag Development Team