Thursday, September 13, 2018

POINTERS -24

  • Problem Description

    Write a function that accepts a string using pointers. In the function ,delete all the occurrences of a given character and display the modified string on the screen

    Input and Output Format:

    Refer sample input and output for formatting specification.

    All float values are displayed correct to 2 decimal places.

    All text in bold corresponds to input and the rest corresponds to output.

  • CODING ARENA
  • #include <stdio.h>
    #include<string.h>
    int main()
    {
      char str[15],ch,cat[10];
      scanf("%s%s",str,cat);
      scanf("%s",&ch);
      int i=0,j,len;
      len=strlen(str);
      for(i=0;i<len;i++)
      {
        if(str[i]==ch)
        {
          for(j=i;j<len;j++)
          {
            str[j]=str[j+1];
          }
          len--;
          i--;
        }
      }
      printf("%s ",str);
      printf("%s",cat);
      return 0;
    }
  • Test Case 1

    Input (stdin)
    SRM University
    
    S
    
    
    Expected Output
    RM University
  • Test Case 2

    Input (stdin)
    SRM University
    
    R
    
    
    Expected Output
    SM University

No comments:

Post a Comment