Substring from a position to length - C Language Programming

Program in C Language to substring from a position to length



Click here to open this program in Turbo C++

/*******************************************************
 Statement - Substring from a position to length
 Programmer - Vineet Choudhary
 Written For - http://developerinsider.co
 *******************************************************/

#include <stdio.h>
#include <conio.h>

void main()
{
    char string[1000], sub[1000];
    int position, length, c = 0;
    clrscr();
    
    printf("Input a string\n");
    gets(string);
    
    printf("Enter the position and length of substring\n");
    scanf("%d%d", &position, &length);
    
    while (c < length) {
        sub[c] = string[position+c-1];
        c++;
    }
    sub[c] = '\0';
    
    printf("Required substring is \"%s\"\n", sub);
    
    getch();
}
You've successfully subscribed to Developer Insider
Great! Next, complete checkout for full access to Developer Insider
Welcome back! You've successfully signed in
Success! Your account is fully activated, you now have access to all content.