Q:

C Program to extract a substring from a given string

0

C Program to extract a substring from a given string

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

#include <stdio.h>
void main() 
{
   char str[100], sstr[100];
   int pos, l, c = 0;
   
       printf("\n\nExtract a substring from a given string:\n");
       printf("--------------------------------------------\n");  
 
       printf("Input the string : ");
       fgets(str, sizeof str, stdin);
 
   printf("Input the position to start extraction :");
   scanf("%d", &pos);
   
   printf("Input the length of substring :");
   scanf("%d", &l);
 
   while (c < l) 
   {
      sstr[c] = str[pos+c-1];
      c++;
   }
   sstr[c] = '\0';
 
   printf("The substring retrieve from the string is : " %s\ "\n\n", sstr);
 
}

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

Similar questions


need a help?


find thousands of online teachers now