/* * dowhile.c */ #include <stdio.h> int main() { char cc; printf("Enter a 'y': "); // prompt for input cc=getchar(); // read from stdin, assing to mem location of cc while(getchar() != '\n'); // keep running test on imput buffer until we get a new line . /* This embedded while test has a semicolon. * It gets characters and does nothing with them. * When it encounters a newline, it quits. */ printf("You entered a '%c'.\n",cc); // output result of getchar while (cc != 'y') // go back into loop unless cc = 'y' { printf("Enter a 'y'. \n"); cc=getchar(); // read from stdin, assing to mem location of cc while(getchar() != '\n'); // keep running test on imput buffer until we get a new line . printf("Yes, a 'y'. thank you. \n"); } printf("You entered a '%c'.\n",cc); // output result of getchar return 0; }