Canna

Tuesday, 25 September 2018

Character Extract

  • Problem Description

    Write a program to extract a portion of a character string and print the extracted string. Assume that m characters are extracted, starting with the nth character.
  • Test Case 1

    Input (stdin)
    SRMUniversityLearningCentre
    
    10
    
    5
    
    
    Expected Output
    niversityL
  • Test Case 2

    Input (stdin)
    SRMuniversity
    
    3
    
    1
    
    
    Expected Output
    SRM
  • Program
  • #include <stdio.h>
    #include <string.h>
    int main()
    {
      char str1[100],str2[100];
      int c=0,m,n;
      scanf("%s",str1);
      scanf("%d",&n);
      scanf("%d",&m);
      while(c<n)
      {
        str2[c]=str1[m+c-1];
        c++;
      }
      str2[c]='\0';
    
        printf("%s",str2);
        return 0;
    }

No comments:

Post a Comment

Note: only a member of this blog may post a comment.