Design and Analysis of Algorithms
| Program to delete a string from a string. |
#include<iostream.h>
#include<stdio.h>
#include<conio.h>
void main()
{
clrscr();
char str[80];
int i,p,n,len;
cout<<"\n enter the string (max 80 character):";
gets(str);
for(len=0;str[len]!='\0';len++);
cout<<"\n enter the starting position of substring to be
deleted:";
cin>>p;
if(p>len)
cout<<"starting position must be less than length of string
aborting!!\n";
else
{
cout<<"\n enter the number of characters of substring to be
deleted:";
cin>>n;
if(n+p>=len)
n=len-p+1;
for(i=p-1;str[i]!='\0';i++)
str[i]=str[i+n];
cout<<"\n string after deletion of substring is:"<<str;
}
getch();
}
| Output: |
enter the string (max 80 character):hello how are you
enter the starting position of substring to be deleted: 6
enter the number of characters of substring to be deleted:4
string after deletion of substring is:hello are you
If any of you want to submit your programs and
contribute to site please mail us at:
citysuvidha@gmail.com
Click here to have a look at List of programs
You can download all the programs in a zip file also. For this you have to do one thing. Just register at the citysuvidha forum and start any thread of any topic. Once you start the thread and put your request, admin will automatically send you the desired zip file.