substring from a string extraction

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

int main()
{
    char str[50], news[50];
    char *s , *t ;
    int pos, i , n ;

    printf(" Enter a string : \n  ");
    gets(str);

    printf(" \n Enter the position and the numbers to be extracted : ");
    scanf("%d%d",&pos,&n);

    s=str;
    t=news;

    if(n == 0)
        n = strlen(str);

    s = s + pos - 1 ;

    for(i =0; i<n ;i++)
    {
        *t = *s;
        s++;
        t++;
    }
    *t = '\0';

    printf(" \n \n The substring is %s \n",news);

    return 0 ;
}

OUTPUT : -



For Other Programs Visit The WebSite:-   https://www.techapurba.com/
                                                                                                                      
Follow Me On Social Media :-
INSTA photography page :- https://www.instagram.com/photo_mania_hub/

Insta photography link :- https://www.instagram.com/photo_mania_hub/
For tech related videos visit my other website :- https://apurbatechinfo.blogspot.com/

Post a Comment

0 Comments