getchar and the input

hello,i want to know that why do we use getchar() before while loop and and when to use it?? like this solution.I dont know when to use getchar().can anyone help??

getchar() just accepts a character.

for better understanding read these

http://www.cplusplus.com/reference/cstdio/getchar/

http://cprogrammingexpert.com/C/Tutorial/io_functions/getchar.aspx

http://rabbit.eng.miami.edu/class/een218/getchar.html

http://en.wikibooks.org/wiki/C_Programming/C_Reference/stdio.h/getchar

Getchar() is used to get ‘\n’ from stdin left after integer input. It is used when there is a string input next to an integer input.

You may read this thread for further explanation.

http://discuss.codechef.com/questions/59719/why-using-getchar-in-the-following-program?page=1#59722

Hope You understood… :slight_smile:

that was very much useful…thanks a lot and yes understood :smiley:

welcome… :slight_smile: