need help to find and delete a string

arunlalds's Avatar, Join Date: Mar 2010
Banned
Write a c++ program to read a string. then accept another string a find the string on string1.if found the delete
ex: independence

pen

final output

indedence
virxen's Avatar, Join Date: Nov 2009
Pro contributor
check this

http://www.cplusplus.com/reference/c...string/strstr/
itstimetojazz's Avatar, Join Date: Sep 2009
Light Poster
Code:
int main()
{         
               char str1[MAX_PATH];
	char str2[MAX_PATH];

	cout<<"Enter a string"<<endl;
	cin>>str1;
	int n1;
	n1=strlen(str1);
	str1[n1]='\0';	//to ensure null characters are eliminated

	cout<<endl;
	cout<<"enter a substring to eliminate"<<endl;
	cin>>str2;

	int n2;
	n2=strlen(str2);
	str2[n2]='\0'; //to ensure null characters are eliminated

	char *pdest;

	pdest=strstr(str1,str2);


	int result1;
	result1=pdest-str1;

	int len=strlen(str2);
	
	//loop to print the initials
	for(int i=0; i<result1;i++)
	{
		cout<<str1[i];
	}

	//print the remaining characters
	cout<<pdest+len<<endl;

return 0;
}

Last edited by shabbir; 18Mar2010 at 19:04.. Reason: Code blocks