by Dinesh Thakur Category: Array
#include <Stdio.h>

#include <conio.h>
int main()
{
   char str[100], substr[100];
   int i=0, j=0, n, m;
   clrscr ();
   printf("\n Enter the main string: ");
   gets (str);
   printf("\n Enter the position from which to start the substring: ");
   scanf ("%d", &m) ;
   printf("\n Enter the length of the substring: ") ;
   scanf ("%d", &n);
   i=m;
   while(str[i] !='\0' &&n>=0)
   {
     substr[j] = str[i];
     i++;
     j ++;
     n--;
   }
      substr[j] = '\0';
      printf ("\n The substring is : ");
      puts (str);
     getch();
    return 0;
}

extract the substring from a given string



About Dinesh Thakur

Dinesh ThakurDinesh Thakur holds an B.SC (Computer Science), MCSE, MCDBA, CCNA, CCNP, A+, SCJP certifications. Dinesh authors the hugely popular blog. Where he writes how-to guides around Computer fundamental , computer software, Computer programming, and web apps. For any type of query or something that you think is missing, please feel free to Contact us.



Related Articles