Using if else statements, reads input up to #, replaces each period with an exclamation mark - C Statement

C examples for Statement:if

Introduction

Replaces each exclamation mark initially present with two exclamation marks, and reports at the end the number of substitutions it has made.

Demo Code

#include <stdio.h>

#define STOP '#'// w w w .java2  s  .  c o m

int main(void){
  char ch;

  printf("Enter input (%c to exit):\n", STOP);

  while ((ch = getchar()) != STOP){
    if (ch == '.')
      printf("!");
    else if (ch == '!')
      printf("!!");
    else
      printf("%c", ch);
  }
  return 0;
}

Result


Related Tutorials