Hello guys I am reading some book but there and went to input validation but there is something logical i dont get in it you know when press enter with getchar() sometimes it transmits newline to the program but book has solution but i don't know why it works i m confused about it
while (getchar() != 'y') /* get response, compare to y */
{
printf("Well, then, is it %d?\n", ++guess);
while (getchar() != '\n')
continue; /* skip rest of input line */
}
but this will discard rest of the line but the \n it wont discard it since the loop will quit when it reads \n ? shouldnt it be while(getchar()=='\n')
continue;
now it will discard it ?
wouldnt it be better to do this
while( we getting char not = eof) {
if(char == '\n')
continue;//wouldnt it be better to use this ?
}
i know first one will discard every character but why does it discard the \n also ?