Sunday, May 12, 2019

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.

  • Test Case 1

    Input (stdin)
    SRM University

    S

    Expected Output
    RM University
  • Test Case 2

    Input (stdin)
    SRM University

    R

    Expected Output
    SM University
  • Program
  • #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;
    }

No comments:

Post a Comment

Parity

Problem Description Ram and Sita playing the parity game. Two types of parity are there. One is odd parity and next is even parity. Ram will...