Impressively written code DaWei, there are a lot of things we can learn from you.
Firstly, I didn't know that we could use scanf's return value like that.
Secondly, I didn't know we could rewind the STDIN, i guess rewind (stdin) clears the screen, please explain this.