Program to extraction of substring program
#include
<stdio.h>
#include
<conio.h>
void
main(){
int m,n,i,len;
char
str[40]="",substr[40]="";
clrscr();
printf("*****SubString
Demo*****\n\n");
printf("Enter string : ");
scanf("%[^\n]s",str);
for(m=0;str[m]!='\0';m++);
len = m;
printf("\nString
Extracting Details\n");
strt:
printf("enter starting position :
");
scanf("%d",&m);
printf("enter ending position :
");
scanf("%d",&n);
if(m<=0 || m>len || n<m || n<=0
|| n>len){
printf("\n\nInvalid
Input\n\n");
goto strt; }
else{
for(i=0;m<=n;m++,i++)
substr[i]=str[m-1];
substr[i]='\0';
printf("\nSub String is
%s",substr);}
getch();
}
No comments:
Post a Comment