You can get rid of the ugly conditional expression loop != ENDLOOP and simplify your program in the process.
#include <stdio.h> int main() { int c; while (EOF != (c = getchar())) { if (c == 'e'|| c == 'E') { printf ("END LOOP\n"); break; } else if (c == 'c' || c == 'C') printf ("Cheese\n"); else printf ("Not Cheese\n"); } return 0; }
The unequal comparison of EOF makes it clear how getchar() can complete the while loop. Otherwise, break does if 'e' or 'E' is taken from stdin.
Int is before the main one, and return 0 is to clear ANSI C, so it's mostly stylistic, but good style.
source share