Remove the semicolon at the end of while condition
How to terminate while loop if character matched '.' in c [closed]
-
02-10-2022 - |
题
char b;
while((b=getchar()) != '.' );
{
printf("%c",b);
}
If I had the following input in stdin abcd.
it should print a then b then c then d then detect the . and terminate although its simply printing a . instead of abcd
解决方案
其他提示
The semicolon at the end of the while loop makes it execute only once . It does not loop at all . Your program is simple a linear program with no looping .
Otherwise your program logic is fine .
不隶属于 StackOverflow