1. We have moved from vBulletin to XenForo and you are viewing the site in the middle of the move. Though the functional aspect of everything is working fine, we are still working on other changes including the new design on Xenforo.
    Dismiss Notice

need help to find and delete a string

Discussion in 'C++' started by arunlalds, Mar 17, 2010.

  1. arunlalds

    arunlalds 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
     
  2. virxen

    virxen New Member

  3. itstimetojazz

    itstimetojazz New Member

    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 a moderator: Mar 18, 2010

Share This Page