Reads input up to # and replaces each period with an exclamation mark, replaces each exclamation mark with two exclamation marks - C Statement

C examples for Statement:while

Introduction

Reports at the end the number of substitutions it has made.

Demo Code

#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;  
}

Result


Related Tutorials