You can argue about the readability of such code (and it will not pass the code review in most places where I worked), but the problem is not what the task is. The problem is that getchar() does not return a char , it returns int . And that set of possible return values ββwill not match the char value. If you change your code in:
int c; while ( (c = getchar()) != EOF && c != '\n' ) { ...
it will be "safe" (but I still donβt want to support it). if you want to update c in the path control use the for loop:
for ( int c = getchar(); c != EOF && c != '\n'; c = getchar() ) { ...
It is at least readable.
source share