C examples for Statement:while
Reports at the end the number of substitutions it has made.
#include <stdio.h> int main(void) { /* ww w . j av a 2 s .c o m*/ char ch; int ct1 = 0; int ct2 = 0; while ((ch = getchar()) != '#') { switch(ch) { case '.' : putchar('!'); ++ct1; break; case '!' : putchar('!'); putchar('!'); ++ct2; break; default : putchar(ch); } } printf("%d replacement(s) of . with !\n", ct1); printf("%d replacement(s) of ! with !!\n", ct2); return 0; }