#include<stdio.h>
int main(){
char ch;
while(1){
ch = getchar();
if(ch =='n'){
break;
}
printf("hello");
}
}
Loop is printing 2 hello's instead of one. while loop is always true and accepts a char from user if the char is n then the loop breaks else it has to print hello and ask for user input again and process. Not able to understand the program behaviour.
echo 'an' | ./loop
prints it once for me. – Stephen Newell