Hello guys, I wanted to understand how this function works. I have used it anyway without [roperly understanding its mechanism to remove a newline(\n) from the stream and get only one Character.
Code:char getch(void) { char ch; ch = getchar(); while(getchar()!='\n') ; return(ch); }
Please explain :
1) How this works? When is the original input taken?
2) Why is the while loop empty?
3) Do functions like scanf(),fgets() leave a trailing \n or \0?
Thank You very much.