1. You prompt for input.
  2. You press 'd' followed by the "Enter" key -> the buffer contains two characters 'd', '/n'.
  3. getchar reads 'd' from the buffer -> buffer contains single character '/n'.
  4. Since 'd' is not '0' you reprompt for input, but the buffer already contains '/n' and program doesn't wait for you to input anything.
  5. getchar reads '/n' from the buffer -> buffer is now empty.
  6. Since '/n' is not '0' you reprompt for input, program waits for user input.

The double print happens because of the green bits above.