Say I have a simple while loop to enter **1*0* characters. After more than 10, I want the loop to stop. However, the break seems not to take effect. Only when I press Enter it ends. Can anyone explain please?
int count = 0; int numchars = 10; ch = getchar(); while( ch != '\n' && ch != '\0' ) { array[count] = ch; count++; if ( count > numchars ){ break; } ch = getchar(); } Thanks.
setvbufto turn off buffering may or may not fix this