Thursday 6 September 2012

/* --- Program to Extract a portion from a String --- */


#include <stdio.h>
#include <conio.h>
main()
{
    char str1[100],str2[100];
    int i,j,m,n;

    clrscr();
    gotoxy(15,2);
    printf("Program on Extracting a Portion from a String \n");
    gotoxy(5,5);
    printf("Enter a Line of Text : ");
    gets(str1);
    gotoxy(5,7);
    printf("Enter Starting & Ending locations : ");
    scanf("%d %d",&m,&n);
    gotoxy(5,9);

/*    Extraction procedure    */

    for(j=0,i=m-1;str1[i]!='\0'&&i<n;i++,j++)
        str2[j]=str1[i];

    str2[j]='\0';    /* Assigning a Null */
    printf("Extracted portion is : %s",str2);
    getch();
}

No comments:

Post a Comment