Friday, August 17, 2018

REMOVE 1st OCCURRENCE

  • Problem Description

    Write a C program to read any string from user and remove first occurrence of a given character from the string.
  • CODING ARENA
  • #include <stdio.h>
    #include<string.h>
    int main()
    {
      char str[100],s;
      scanf("%s%s",str,&s);
      int i,len;
      i=0;
      len=strlen(str);
      while(i<len && str[i]!=s)
      {
        i++;
      }
      while(i<len)
      {
        str[i]=str[i+1];
        i++;
      }
      printf("%s",str);
      

    return 0;
    }
  • Test Case 1

    Input (stdin)
    srmuniversitylearningcentre
    
    i
    
    
    Expected Output
    srmunversitylearningcentre
  • Test Case 2

    Input (stdin)
    SRASRASRA
    
    A
    
    
    Expected Output
    SRSRASRA

No comments:

Post a Comment